zoukankan      html  css  js  c++  java
  • js获取select标签选中的值

    <select name="" id="testSelect" onclick="test2()">
    <option value="1">a</option>
    <option value="2">b</option>
    <option value="3">c</option>
    <option value="4">d</option>
    </select>
    <script src="js/jquery.min.js"></script>
    <script>


    function test(){
    var obj = document.getElementById("testSelect"); //定位id
    console.log(obj);
    var index = obj.selectedIndex; // 选中索引
    console.log(index);
    var text = obj.options[index].text; // 选中文本
    console.log(text);
    var value = obj.options[index].value; // 选中值
    console.log(value);
    }
    function test1(){
    console.log($('#testSelect option:selected').text());//选中的文本

    console.log($('#testSelect option:selected') .val());//选中的值

    console.log($("#testSelect ").get(0).selectedIndex);//索引
    }
    function test2(){
    console.log($("#testSelect").find("option:selected").text());//选中的文本
    console.log($("#testSelect").find("option:selected").val());
    console.log($("#testSelect ").get(0).selectedIndex);
    }
    </script>

  • 相关阅读:
    Android Native Hook技术(一)
    Android Native Hook技术(二)
    Dalvik源码阅读笔记(一)
    Dalvik源码阅读笔记(二)
    Android反调试笔记
    /dev/mem可没那么简单
    jenkins使用邮件功能
    docker 安装 oracle
    jstack
    docker network
  • 原文地址:https://www.cnblogs.com/studyh5/p/7744088.html
Copyright © 2011-2022 走看看