<html>
<body>
<form id="myForm">
电子邮件:<input type="email" id="myEmail">
</form>
<p>单击该按钮可显示电子邮件字段所属表单的 ID。</p>
<button onclick="myFunction()">试一试</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myEmail").form.id;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>