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

首頁 > 編程 > JavaScript > 正文

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

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

在編程過程中,我們對下拉列表框的取值很多時候都是獲取option中的value,但是也有需要獲取顯示在頁面中的值的時候,例如想獲得<option value="value">ShowText</option>中"ShowText",我們該如何獲取呢?方法很簡單,具體代碼如下:

復制代碼 代碼如下:

<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 下標0、1、2
            var selectValue2 = selectPress.options[selectPress.selectedIndex].innerText; //顯示顯示的值 具體內容(上海、北京)
            //alert(selectValue);
            //alert(selectValue2);
            if (selectValue == "-1") {
                alert("請選擇城市,表單提交被拒絕!")
                return;
            }
            else {
                document.getElementById('form1').submit(); //form表單提交
            }
        }

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长顺县| 宕昌县| 渭南市| 兴隆县| 巨鹿县| 绥宁县| 柳州市| 镇康县| 富顺县| 罗定市| 隆德县| 马边| 甘泉县| 德钦县| 宁津县| 万盛区| 十堰市| 北票市| 兴海县| 威信县| 井冈山市| 乐至县| 苏尼特左旗| 原阳县| 锡林浩特市| 安宁市| 铜川市| 昌吉市| 河北区| 肥乡县| 江山市| 屏东县| 进贤县| 星子县| 张家川| 高密市| 广安市| 开远市| 平武县| 德庆县| 东安县|