this.options[selectedIndex]的使用
来源:互联网 发布:淘宝主板交换对发 编辑:程序博客网 时间:2024/05/13 12:33
<select id="sel" onchange="javascript:getSelect();"><option value="a">选择</option><option value="bdd">be</option><option value="c">ce</option><option value="d">de</option><option value="e">ee</option></select><script>function getSelect() { //得到select下拉列表中option的value var optionValue = document.getElementById("sel").options[document.getElementById("sel").options.selectedIndex].value; //得到select下拉列表中option的text var optionText = document.getElementById("sel").options[document.getElementById("sel").options.selectedIndex].text; }</script><select id="sele" onchange="javascript:getE();"><option value="monday">星期一</option><option value="tuesday">星期二</option><option value="wednesday">星期三</option><option value="thursday">星期四</option><option value="friday">星期五</option></select><script>function getE() { //我建议这里也像下面一些写,虽然这样写也可以获得数据 var optionsValue = document.getElementById("sele").value; alert(optionsValue); var optionsText = document.getElementById("sele").options[document.getElementById("sele").options.selectedIndex].text; alert(optionsText);}</script>