查找按钮的值

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <form id="frm1" action="/demo/action_page.php">
  6. <button id="btn1" name="subject" type="submit" value="fav_HTML">HTML</button>
  7. <button id="btn2" name="subject" type="submit" value="fav_CSS">CSS</button>
  8. </form>
  9.  
  10. <p>单击“试一试”按钮返回“HTML”按钮的值:</p>
  11.  
  12. <button onclick="myFunction()">试一试</button>
  13.  
  14. <p id="demo"></p>
  15.  
  16. <script>
  17. function myFunction() {
  18. var x = document.getElementById("btn1").value;
  19. document.getElementById("demo").innerHTML = x;
  20. }
  21. </script>
  22.  
  23. </body>
  24. </html>