怎样将从数据库中读取的数据显示在select的option中

怎样将从数据库中读取的数据显示在select的option中,第1张

怎样将从数据库中读取的数据显示在select的option中

如果是要用js进行加载,建议不要写成list,js貌似不能取list的值吧。将值存放在数组中。

function xx(value){

for(var i=0i<value.lengthi++){var option=document.createElement("option")

document.getElementById("select").appendChild(option)

option.value=i+1 //每个option的位置

option.text=value[i]//每个Option的值

}

}

页面body中加载onload=xx(<%request.setAttribute("name")%>)

比如一张表中有2个字段,id和name,现在你把这张表中的所有的值都取出来放在一个二维数组$arr中了,那么现在来遍历这个$arr数组

echo "<select name=''>"

foreach($arr as $key=>$vo){

    echo "<option value=$vo['id']>$vo['name']</option>"

}

echo "</select>"

遍历就是这样了,当然我是用echo 输出的了,记得要写在一对<select></select>的里面

<select name="stu.stu_teacher" id="stu.stu_teacher"/>

<option value="<s:property value='#session.student.stu_teacher'/>" selected><s:property value='#session.student.stu_teacher'/></option>

<s:iterator value="#session.teacher" id="teacher">

<option value="<s:property value='#teacher.teacher_name'/>"><s:property value='#teacher.teacher_name'/></option>

</s:iterator>

</select>

我用的s标签,你改成c标签试试


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/10864011.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-11
下一篇2023-05-11

发表评论

登录后才能评论

评论列表(0条)

    保存