|
IE,FireFox下通过测试:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>测试</title> <script language="javascript" type="text/javascript"> function validate() { for (var i = 0; i < document.getElementById("selectMenu").options.length; i++) { if (document.getElementById("selectMenu").options[i].selected && ( document.getElementById("selectMenu").options[i].text == "不能删1" || document.getElementById("selectMenu").options[i].text == "不能删2") ) { window.alert("不可删除!"); return false; } } return true; } </script> </head>
<body> <form id="test" method="post" action="" onsubmit="return validate();"> <select id="selectMenu" name="selectMenu"> <option value="1">不能删1</option> <option value="2">不能删2</option> <option value="3">3</option> <option value="4">4</option> </select> <input type="submit" name="Submit" value="提交" /> </form> </body> </html>
注意其中“document.getElementById("selectMenu").options.text”还可以是: document.getElementById("selectMenu").options.innerHTML document.getElementById("selectMenu").options.value
这三项中,除了“document.getElementById("selectMenu").options.value”表示选项“value="4"”的值外,其它两项均表示网页上可见的选项值“4”。
|
一共有 0 条评论