1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > js获取Listbox选择的值

js获取Listbox选择的值

时间:2023-12-06 01:39:36

相关推荐

js获取Listbox选择的值

将Listbox的 SelectionMode="Multiple",设置为多选时,用JS获取多选的值。

<script type="text/javascript">function GetValue() {var strlist = document.getElementById("ListBox1");//获取Listboxvar str= "";//遍历Listbox,取得选中项的值if (strlist.options.length > 0) {for (var i = 0; i < strlist.options.length; i++) {if (strlist.options[i].selected == true) {var j = strlist.options[i].value;str+=j+","; //把Value值串起来}}var strValue=str.replace(/,$/, ""); //去掉最后一个逗号alert(strValue);}else {alert("No Item in Listbox");}}</script>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。