得到多選框中所有項的值
阿新 • • 發佈:2019-02-10
<html>
<head>
<script language="javascript">
<!--
function getData(thisform){
var temp = thisform.myValue.length;
for(var i=0;i<temp;i++){
alert(thisform.myValue[i].value); //取得所有的值
alert(thisform.myValue[i].text); //取得所有的select文字
}
}
//-->
</script>
</head>
<body>
<form name="frm01">
<select name="myValue">
<option value=1>22</option>
<option value=3>f23</option>
<option value=6>2f2</option>
<option value=yh>2f2</option>
<option value=5>2ff2</option>
</select>
<input type="button" value="hello" onclick="getData(document.frm01);">
</form>
</body>
</html>
<head>
<script language="javascript">
<!--
function getData(thisform){
var temp = thisform.myValue.length;
for(var i=0;i<temp;i++){
alert(thisform.myValue[i].value); //取得所有的值
alert(thisform.myValue[i].text); //取得所有的select文字
}
}
//-->
</script>
</head>
<body>
<form name="frm01">
<select name="myValue">
<option value=1>22</option>
<option value=3>f23</option>
<option value=6>2f2</option>
<option value=yh>2f2</option>
<option value=5>2ff2</option>
</select>
<input type="button" value="hello" onclick="getData(document.frm01);">
</form>
</body>
</html>