源代码:
下载代码
AI 编程工具
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <body> <form id="runoob-form"> <textarea id="myTextarea"> Runoob</textarea> </form> <p>点击按钮查看 textarea 所属的表单 id。</p> <button type="button" onclick="myFunction()">点我</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myTextarea").form.id; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
运行结果: