最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

js獲取下拉列表框<option>中的value和text的值示例代碼

 更新時(shí)間:2014年01月11日 09:52:34   作者:  
本篇文章主要是對(duì)js獲取下拉列表框<option>中的value和text的值示例代碼進(jìn)行了介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助

在編程過(guò)程中,我們對(duì)下拉列表框的取值很多時(shí)候都是獲取option中的value,但是也有需要獲取顯示在頁(yè)面中的值的時(shí)候,例如想獲得<option value="value">ShowText</option>中"ShowText",我們?cè)撊绾潍@取呢?方法很簡(jiǎn)單,具體代碼如下:

復(fù)制代碼 代碼如下:

<script type="text/javascript">
function a(object){
alert(object);
}
</script>

<!-- 獲取顯示的值 -->
<select onchange="a(this.options[this.selectedIndex].innerText);">
<option value="value-a">text-a</option>
<option value="value-b">text-b</option>
</select>

<!-- 獲取value的值 -->
<select onchange="a(this.options[this.selectedIndex].value);">
<option value="value-c">text-c</option>
<option value="value-d">text-d</option>
</select>

function isSelect(selectPress) {
            //var select = document.getElementById("mySelect").ind;
            var selectValue = selectPress.options[selectPress.selectedIndex].value; //顯示value 下標(biāo)0、1、2
            var selectValue2 = selectPress.options[selectPress.selectedIndex].innerText; //顯示顯示的值 具體內(nèi)容(上海、北京)
            //alert(selectValue);
            //alert(selectValue2);
            if (selectValue == "-1") {
                alert("請(qǐng)選擇城市,表單提交被拒絕!")
                return;
            }
            else {
                document.getElementById('form1').submit(); //form表單提交
            }
        }

<select onchange="isSelect(this);" id="mySelect">
        <option value="-1">--請(qǐng)選擇--</option>
        <option value="0">北京</option>
        <option value="1">上海</option>
        <option value="2">武漢</option>
</select>

相關(guān)文章

最新評(píng)論

海晏县| 洛川县| 周口市| 哈巴河县| 曲阳县| 美姑县| 仙游县| 凯里市| 高雄县| 绥化市| 耒阳市| 五指山市| 阜康市| 合水县| 娱乐| 浦北县| 黑河市| 泰州市| 陕西省| 万荣县| 大厂| 辽宁省| 昭平县| 清河县| 眉山市| 资溪县| 轮台县| 鸡西市| 东平县| 淮阳县| 天祝| 和静县| 霍邱县| 岱山县| 苏州市| 缙云县| 秦皇岛市| 会同县| 辽源市| 伊宁县| 沁阳市|