我正在尝试使用以下代码验证一个简单的表单,但我不断收到以下错误:错误:无法获取未定义或空引用的属性“替换”。我究竟做错了什么?
JavaScript:
var test = function(){
var e = document.getElementsByTagName("*");
for (var i = 0; i < e.length; i++){
var t = e[i].getAttribute("type");
var n = e[i].tagName;
var v = e[i].value.replace(" ", "");
if (v === "" && (n === "input" && (t === "text" || t === "tel" || t === "email") || n === "select")){
alert("Please Fill Out All Fields");
return false;
}
}
}
HTML:
<form id="form1" runat="server" onsubmit="test();">
<div style="padding-left:50px; padding-top:50px;">
<div>
<input type="text" />
<br />
<br />
<input type="text" />
<br />
<br />
<button type="submit" id="submit">Submit</button>
</div>
</div>
</form>