国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

javascript獲取select的當前值示例代碼(兼容IE/Firefox/Opera/Chrome)

2019-11-20 21:26:58
字體:
來源:轉載
供稿:網友

JavaScript獲取Select當前值寫法:
var value = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].value;
var text = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].text;

例子:

復制代碼 代碼如下:

<script>
function check() {
      var select = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].value;
      alert(select);
}
</script>

<select name="select" id="select">
<option value="test1" selected="selected">Test1</option>
<option value="test2">Test2</option>
</select>
<input type="button" value="我要試試" onclick="check()"/>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 淮南市| 凤台县| 乡城县| 彩票| 阿尔山市| 武宣县| 德惠市| 西充县| 太保市| 阜城县| 宁城县| 松溪县| 衡南县| 定边县| 普格县| 巨野县| 峡江县| 桓仁| 新丰县| 怀柔区| 高安市| 南城县| 屏东县| 德昌县| 碌曲县| 乌拉特前旗| 湖口县| 大荔县| 廊坊市| 呼和浩特市| 苍山县| 天峨县| 公安县| 曲阜市| 随州市| 霍林郭勒市| 宣汉县| 敦煌市| 宁海县| 新野县| 太和县|