<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Javascript Form Testing</title>
</head>
<body>
Name: <input type="text" name="Name" value="Name" id="fname"> <br>
Email: <input type="text" name="Email" value="Email" id="mail" > <br>
Phone: <input type="text" name="Number" value="Phone Number" id="dvr" onchange="validatePhone();">
<span id="phoneval"> ?</span>
<script type="text/javascript">
phonenum = document.getElementById("dvr").value.length;
function validatePhone() {
if (phonenum == 10){
document.getElementById('phoneval').innerhtml="<-- Valid";
}
else{
document.getElementById('phoneval').innerhtml="<-- Not Valid";
}
}
</script>
</body>
</html>
嗨,当标签位于头部时,我收到错误“Uncaught TypeError: Cannot read property 'value' of null”,但由于我移动了它,它就消失了。但是,现在它没有输出错误并且什么都不做。请帮忙?
对不起任何格式和东西,新的:/