JS 獲取select (多選下拉)中所選中的值

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
 </head>


 <body>


<script language="JavaScript">
  <!--
function checkselect(objname){
    o = document.getElementById(objname);
    t = document.getElementById("output");
var count=0;
    var intvalue="";
    for(i=0;i<o.length;i++){   
        if(o.options[i].selected){
            intvalue+=o.options[i].value+",";
count++;
        }
    }
    t.value=intvalue.substr(0,intvalue.length-1);
alert(count);


}
  //-->
  </script>
  <select name="objsel" size=8 multiple>
    <option value="0" selected>請選擇
    <option value="1">測試一
    <option value="2">測試二
    <option value="3">測試三
    <option value="4">測試四
    <option value="5">測試五
  </select>
<input type="button" οnclick="checkselect('objsel');" value="輸出">
選中的項目:<input type="text" name="output">
 </body>
</html>
發佈了37 篇原創文章 · 獲贊 9 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章