1. Home
  2. Docs
  3. JQUERY
  4. HTML Forms 元件
  5. Input Text的設定和取得

Input Text的設定和取得

    <!DOCTYPE html>
    <html>
    <head>
    <script src="httpsss://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
      $("button#div1").click(function(){
        $("input:text").val("powenko");
      });
      $("button#div2").click(function(){
        t1=$("input:text").val();
        alert(t1);
      });
    });
    </script>
    </head>
    <body>
    
    <p>Name: <input type="text" name="user"></p>
    
    <button id="div1">Set the value of the input field</button>
    <button id="div2">get the value of the input field</button>
    
    </body>
    </html>