查找按钮的值
- <!DOCTYPE html>
- <html>
- <body>
- <form id="frm1" action="/demo/action_page.php">
- <button id="btn1" name="subject" type="submit" value="fav_HTML">HTML</button>
- <button id="btn2" name="subject" type="submit" value="fav_CSS">CSS</button>
- </form>
- <p>单击“试一试”按钮返回“HTML”按钮的值:</p>
- <button onclick="myFunction()">试一试</button>
- <p id="demo"></p>
- <script>
- function myFunction() {
- var x = document.getElementById("btn1").value;
- document.getElementById("demo").innerHTML = x;
- }
- </script>
- </body>
- </html>