JS获取select-option-text

时间:2016.05.06 发布人:ghfdz

JS获取select-option-text

已解决问题

谷歌ghfdz用户在2016.05.06提交了关于“浙江男篮战胜JS获取select-option-text”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2025-01-25T08:08:14。希望大家能够帮助她。

详细问题描述及疑问:期待您的答案,滴水之恩,来日我当涌泉相报 !

希望以下的回答,能够帮助你。

第1个回答

用户名:Rainkey11  

这篇文章主要介绍了JS获取select-opti331215问答on-text_value的方法,有需要的朋友可以参考一下

h**TML代码:代码如下:<selectid="month"o乱令卷移花海持果愿征倍nchange="selectInput(this)"><optionvalue="01">Ja**ary</option><optionvalu安间套春参庆起治e="02">February</option><optionvalue="03">March</option><optionvalue="04">April</option><optionvalue="05">May</option><optionvalue="06">Ju期利复伤ne</option><optionvalue="07">July</option><optionvalu端歌开率充言e="08"selec模做迫陆ted="selected">A望帮介ugust</option><optionvalue="09">September</option><optionvalue="10">October</op变仍导和纸见杨室所请机tion><optionvalue="11">November</o利你题ption><optionvalue="12">December</option></select>用jQuery获取select选中对象的value、text代码如下:$(function(){$("#month").change(function(){alert($(this).find("option:selected").val());alert($(this).find("option:selected").text());});});如果用JS获取甚磁陈婷终现极宪重select选中对象的value是很容易的代码如下属走走圆又别座:functionselectInput(oS称注跑衡已文仅elect){alert(oSelect.value);}如果要用JS获取select选中对象的text呢?代码如下:functionselectInput(oSelect){alert(各来oSelect.options[oSelect.selectedIndex].text);}如果select没有默认则设第一个为默认?代码如下:d言ocument.getElementById("test“).options[0].selected=true;