查找表单的目标(target)

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <form id="frm1" action="/demo/demo_form.asp" target="_self">
  6. 名:<input type="text" name="fname" value="Bill"><br>
  7. 姓:<input type="text" name="lname" value="Gates"><br><br>
  8. <input type="submit" value="提交">
  9. </form>
  10.  
  11. <p>点击“试一试”以显示表单的目标:</p>
  12.  
  13. <button onclick="myFunction()">试一试</button>
  14.  
  15. <p id="demo"></p>
  16.  
  17. <script>
  18. function myFunction() {
  19. var x = document.getElementById("frm1").target;
  20. document.getElementById("demo").innerHTML = x;
  21. }
  22. </script>
  23.  
  24. </body>
  25. </html>