<html> <head> <script type="text/javascript"> function formAction() { var x=document.getElementById("mySelect") x.multiple=true } </script> </head>
<body> <p> Before you click on the "Select multiple" button, try to select more than one option (by holding down the shift or Ctrl key). Click on the "Select multiple" button and try again. </p> <form> <select name="mySelect" size="3"> <option>Apple</option> <option>Banana</option> <option>Orange</option> </select> <input type="button" onclick="formAction()" value="Select multiple"> </form> </body>
</html>
返回所选列表的文本值
<html> <head> <script type="text/javascript"> function getText() { var x=document.getElementById("mySelect") alert(x.options[x.selectedIndex].text) } </script> </head>
<body> <form> Select your favorite fruit: <select id="mySelect"> <option>Apple</option> <option>Orange</option> <option>Pineapple</option> <option>Banana</option> </select> <br /><br /> <input type="button" onclick="getText()" value="Show text of selected fruit"> </form> </body>
</html>
删除列表的项目
<html> <head> <script type="text/javascript"> function formAction() { var x=document.getElementById("mySelect") x.remove(x.selectedIndex)