1 回答
TA贡献1772条经验 获得超5个赞
那是因为这条线document.write('Submitted Data');。document.write删除现有的 html,以便在您使用的下一行中document.getELementById找不到 dom 元素
function myFunc() {
var firstname = document.getElementById("fname").value;
var lastname = document.getElementById("lname").value;
document.writeln("Your full name is:" + firstname + lastname);
}
<body bgcolor="Lightskyblue">
<br>
<br>
<form>
<label> Firstname </label>
<input type="text" name="firstname" id="fname" size="15" /> <br> <br>
<label> Lastname</label>
<input type="text" name="lastname" id="lname" size="15" /> <br> <br>
<label>
Gender :
</label><br>
<input type="radio" name="male" /> Male <br>
<input type="radio" name="female" /> Female
<br>
<br>
<input type="button" value="Submit" onclick="myFunc()" />
</form>
</body>
添加回答
举报