zl程序教程

您现在的位置是:首页 >  后端

当前栏目

JS获取下拉列表所选中的TEXT和Value的实现代码

JS列表代码 实现 获取 value Text 选中
2023-06-13 09:15:15 时间
如下所示:
复制代码代码如下:

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>无标题文档</title>
<scripttype="text/javascript">
functionselChange(){
   varsel=document.getElementById("sel");   
   alert(sel.options[sel.selectedIndex].text);
   alert(sel.options[sel.selectedIndex].value);
}
</script>
</head>
<body>
<selectid="sel"onchange="selChange()">
<optionvalue="zhangsan">张三</option>
<optionvalue="lisi">李四</option>
<optionvalue="wangwu">王五</option>
</select>
</body>
</html>