每当我在页面中放置这个javascript时,它会在IE7或IE8中导致this error,我不知道它有什么问题,起初它是在页面的头部区域,但后来我把它移到了在身体标签之后,在一些谷歌搜索后添加了defer = defer。
如果删除JavaScript,一切正常。
<form name="myform" method ="POST" onsubmit="return validateForm();">
<table border="0" width="600px">
<tr>
<td>Name:</td>
<td><input name="name" type="text" id="name"/></td>
<td>Company:</td>
<td><input name="company" type="text" id="company"/></td>
<td> </td>
</tr>
<tr>
<td>Email Address:</td>
<td><input name="email" type="text" id="email"/></td>
<td></td>
<td></td>
<td> </td>
</tr>
<tr>
<td><input type="radio" value="I Agree" name="myradiobutton" />
I Agree</td>
<td> </td>
<td><input type="radio" value="I Disagree" name="myradiobutton" />
I Disagree</td>
<td> </td>
<td><input type="submit" name="submitit"" value="Submit" /></td>
</tr>
</table>
</form>
</div>
</body>
<script defer="defer" type="text/javascript">
function validateForm()
{
var x=document.forms["myform"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
{
alert("Not a valid e-mail address");
return false;
}
}
</script>
答案 0 :(得分:3)
我认为问题可能与使用defer属性有关而没有在js中提供相应的src属性。
尝试将validateForm()放入名为validate.js的脚本中,然后使用
<script defer="defer" src="validate.js" type="text/javascript"></script>
This post has more information and additional links on IE/defer