JavaScript 参考手册
Submit form 属性
下面的例子将返回该确认按钮所属的表单的 id
源代码:
点击运行 »
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>蜜蜂教程(mifengjc.com)</title> <script> function displayResult() { var x = document.getElementById("submit1").form.id; alert(x); } </script> </head> <body> <form id="form1"> Email: <input type="text" id="email"> <input type="submit" id="submit1"> </form> <button type="button" onclick="displayResult()">显示所属表单的ID</button> </body> </html>
运行结果:
点击运行 »