属性:
<html>
<body>
<select id=test style="display:none"></select>
<script>
for (var i in test.options)
document.writeln(i+"<br>")
</script>
</body>
</html>要知道一个option是否被选中访问它的selected属性就行了
<html>
<body>
<select id=test style="display:none"></select>
<script>
for (var i in test.options)
document.writeln(i+"<br>")
</script>
</body>
</html>要知道一个option是否被选中访问它的selected属性就行了
<script>
function compare()
{
for(i=0;i<document.all.people.options.length;i++)
if(document.all.people.options[i].selected)
alert(document.all.people.options[i].text+"被选中了!");
}
</script>
choose people:
<select name=people multiple onchange=compare()>
<option value=1>ballack
<option value=2>kahn
<option value=3>ziege
<option value=4>klose
</select>
<body>
<select id=test onchange="findSelected()">
<option>abc</option>
<option>bcd</option>
<option>cde</option>
</select>
<script>
function findSelected()
{
with (test)
{
for (var i=0;i<options.length;i++)
if (options[i].selected)
alert(options[i].innerText)
}
}
</script>
</body>
</html>
<!--
function CountItem() {
var Count=0;
for(i=0;i<TheSelect.length;i++)
if(TheSelect.options[i].selected==true) //判断是否选中
Count++;
alert("共有["+Count+"]项被选中!!!");
}
-->
</Script>
<Body>
<Select Name="TheSelect" Multiple>
<Option>China</Option>
<Option>Japan</Option>
<Option>Korea</Option>
<Option>U.S.A</Option>
</Select>
<Input Type=Button Value="统计" OnClick="CountItem()">
</Body>
</Html>