js 获取Listbox选择的值的代码_Javascript教程-查字典教程网
js 获取Listbox选择的值的代码
js 获取Listbox选择的值的代码
发布时间:2016-12-30 来源:查字典编辑
摘要:复制代码代码如下:functionGetValue(){varstrlist=document.getElementById("ListBo...

复制代码 代码如下:

<script type="text/javascript">

function GetValue() {

var strlist = document.getElementById("ListBox1");//获取Listbox

var 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>

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新Javascript教程学习
    热门Javascript教程学习
    编程开发子分类