如何判断
<s:select multiple="true" list="acceptors" id = "lst"/>
中某一项是否被选中?
我用
if (document.getElementById("lst").options[i].selected)不行, 是否该方法不行,
求助
<s:select multiple="true" list="acceptors" id = "lst"/>
中某一项是否被选中?
我用
if (document.getElementById("lst").options[i].selected)不行, 是否该方法不行,
求助
no selected
else
already selected
var fromList = document.getElementById(idName);
for (var i = 1; i < fromList.options.length; i ++) {
if (fromList.options[i].selected) {
toList.options.add(new Option(fromList.options[i].text, fromList.options[i].value));
}
}我这样写问题在哪?
没有选 其他就是选了
if(document.getElementById("lst").selectIndex==i)
其中i为你要判断是否被选中的项,如果被选中,表达式的值会为真,否则为假。
<tr>
<td height="25" class="td_gray"> 接受人:</td>
<td class="td_white" style="vertical-align: middle" width="110px">
<s:select cssStyle="width:100px;height:200px" multiple="true" list="acceptors" listKey="key" id="acceptor" listValue="value" name="task.acceptor" onchange="change(this.value)"/>
</td>
<td class="td_white" width="100" style="padding-left: 5px;">
<input type="button" onclick="changeAcceptor('acceptor', 'toList', 'addAll')" value="全部添加 >>"/><br/><br/>
<input type="button" onclick="changeAcceptor('acceptor', 'toList', 'add')" value="添加 >"/><br/><br/><br/>
<input type="button" onclick="changeAcceptor('acceptor', 'toList', 'deleteAll')" value="<< 全部删除"/><br/><br/>
<input type="button" onclick="changeAcceptor('acceptor', 'toList', 'delete')" value="< 删除"/>
</td>
<td class="td_white">
<s:select id="toList" cssStyle="width:100px;height:200px" multiple="true" list="{}" />
</select>
</td>
</tr>function changeAcceptor(fromListId, toListId, type){
var fromList = document.getElementById(fromListId);
var toList = document.getElementById(toListId);
if (type == "addAll") {
for (var i = 1; i < fromList.options.length; i ++) {
toList.options.add(new Option(fromList.options[i].text, fromList.options[i].value));
}
}
else if (type == "add") {
for (var n = 0; n < fromList.options.length; n ++) {
if (fromList.options[n].select) {
toList.options.add(new Option(fromList.options[n].text, fromList.options[n].value));
}
}
}
else if(type == "deleteAll") {
for (var j = 0; j < toList.options.length; j ++) {
fromList.options.add(new Option(toList.options[j].text, toList.options[j].value));
}
}
else {
for (var k = 0; k < toList.options.length; k ++) {
if (toList.options[k].selected) {
fromList.options.add(new Option(toList.options[k].text, toList.options[k].value));
}
}
}
}
我这样写有问题吗? 问题在哪? 怎么执行不行?
在页面中显示出来的只有2条记录,但是遍历的时候总是有3条记录,第一条为空的?
for(var i=0; i<selected.length;i++){
if(selected[i].checked == true){
if(i == ?){
alert("选中!");
break;
}
}
}
用循环试试...
<select id="acceptor" style="width: 100px; height: 200px;" multiple="multiple">
<option value="张龙飞">张龙飞</option>
<option value="姚双喜">姚双喜</option>
</select>但是document.getElementById("acceptor").options.length是3.
谁能告诉我是什么原因呢?