select 如何拿到我選擇的option里面的值


問題:

我需要向后台傳遞表單里我選擇的select里面的值,那我應該怎么獲取里面的值呢?

 

解答:

<!doctype html>

<html >

  <head>

    <meta charset="UTF-8">

    <title>拿到select里的值</title>

  </head>

  <body>

    <form>

      <select id="test1" onchange="check()">

        <option value="check1">選擇1</opiton>

        <option value="check2">選擇2</opiton>

        <option value="check3">選擇3</opiton>

      </select>

    </form>    

    <script>

      function check(){

      var r = getElementById("test1").value;

      alert(r);

      }

    </script>

  <body>

</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM