<select name="selectzg1" id="selectzg1"
style="width:200;display:none" onchange="changezg(this);ch();">
</select>
<select name="selectzg2" id="selectzg2"
style="width:200;display:none" onchange="changezg(this)">
</select>
List zg1 = this.getHanton().getEmployeeDAO().getLetterName(
this.getSessionComCode(request));
List zg2 = new ArrayList();
StringBuffer sb1 = new StringBuffer();
sb1.append("<option value='all'>全部资格证书</option>");
StringBuffer sb2 = new StringBuffer();
sb2.append("<option value='all'>全部资格证书</option>");
for (int i = 0; i < zg1.size(); i++) {
String[] str1 = zg1.get(i).toString().split(",");
String letter = str1[0].substring(13);
sb1.append("<option value='" + letter + "' class='d" + i + "'>");
sb1.append(letter);
sb1.append("</option>");
zg2 = this.getHanton().getEmployeeDAO().getCompNameByLetter(
this.getSessionComCode(request), letter);
for (int j = 0; j < zg2.size(); j++) {
String[] str2 = zg2.get(j).toString().split(",");
String comp = str2[0].substring(11);
sb2.append("<option value='" + comp + "' class='d" + i + "_"
+ j + "'>");
sb2.append(comp);
sb2.append("</option>");
sb2.append("");
}
}
this.setAttribute(request, "zgselect1", sb1.toString());
this.setAttribute(request, "zgselect2", sb2.toString());为什么前台页面下拉控件为空白? 我设置断点查看了,sb1、sb2的值都是正确的<option></option>的格式。
如果没有改成如下
<select name="selectzg1" id="selectzg1"
style="width:200;display:none" onchange="changezg(this);ch();">
${"zgselect1"}
</select>
<select name="selectzg2" id="selectzg2"
style="width:200;display:none" onchange="changezg(this)">
${"zgselect2"}
</select>
sb2得到的是String字符串(<option value="" id="">XXX</option>),这样的格式吗?
如果是
写一个<div id="aa"></div> 或<span id="a"></span>function aaaaa(){
document.getElementById('aa').innerHTML=
"<select name='' id='id'>
<option value=''></option></select>";
document.getElementById('id').value=值;}将你要组成的<select>放到<div>或<span>中
我sb1、sb2的格式是<option value='' id='' class=''></option>
你的值不是写到request里面了吗?页面就可以取值了。<input id="id" name="" value="" type="hidden"/>js取值:
document.getElementById('id').value;
请求-->对应java代码的Servlet -->对应代码的jsp
2 jsp改成如下
<select name="selectzg1" id="selectzg1"
style="width:200;display:none" onchange="changezg(this);ch();">
${"zgselect1"}
</select>
<select name="selectzg2" id="selectzg2"
style="width:200;display:none" onchange="changezg(this)">
${"zgselect2"}
</select>
<input type='hidden' id='zgzs1' name='zgzs1' value=''>
<input type='hidden' id='zgzs2' name='zgzs2' value=''>
this.setAttribute(request, "zgzs1", sb1.toString());
this.setAttribute(request, "zgzs2", sb2.toString());难道这两句往JSP传值的话有毛病?
我js中 alert(document.getElementById('zgzs1').value);
alert(document.getElementById('zgzs2').value);
弹出的结果仍然为空
style="width:200;display:none" onchange="changezg(this);ch();">
通过el 比如c:foreach把你保存在 requet 的东西用输出来
</select>
<input type='hidden' id='zgzs1' name='zgzs1' value='${requestScope.zgzs1}'>
<input type='hidden' id='zgzs2' name='zgzs2' value='${requestScope.zgzs2}'>value 值给它们
后面不用改
只有前面改成这样就好了<select name="selectzg1" id="selectzg1"
style="width:200;display:none" onchange="changezg(this);ch();">
"${zgselect1}"
</select>
<select name="selectzg2" id="selectzg2"
style="width:200;display:none" onchange="changezg(this)">
"${zgselect2}"
</select>4楼和19楼就差在双引号的位置上了,结贴给分,谢谢大家