<html>
<body>
<form id="myForm">
<label id="myLabel" for="male">Male</label>
<input type="radio" name="sex" id="male" value="male"><br>
</form>
<p>点击“尝试一下”按钮返回 label 所属的表单的 id。</p>
<p id="demo"></p>
<button onclick="myFunction()">尝试一下</button>
<script>
function myFunction()
{
var x = document.getElementById("myLabel").form.id;
document.getElementById("demo").innerHTML=x;
}
</script>
</body>
</html>