查找按钮上显示的文本
- <!DOCTYPE html>
- <html>
- <body>
- <form id="frm1" action="/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").innerHTML;
- document.getElementById("demo").innerHTML = x;
- }
- </script>
- </body>
- </html>