日期:2014-05-16  浏览次数:20462 次

html导入独立的js文件出错,无法调用function,求教!
js文件代码如下:

<script type="text/javascript">
var email;
var bemail="0"; // boolean value to check correctness
... ... // other parameters

function chkEmail(email){ // use AJax for dynamic checking
  this.email=email;
  var xmlhttp;
  if (window.XMLHttpRequest) {
  xmlhttp=new XMLHttpRequest();
  }
  else {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function() { 
  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
  document.getElementById("email").innerHTML=xmlhttp.responseText;
  }
  }
  if (/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(this.email)){ // regular expression checking
  bemail="1"; // to tell the web page the input is in right format
  xmlhttp.open("GET","chkemail.jsp?email="+email,true); xmlhttp.send();
  }
  else{
  bemail="0"; // to tell the web page the input is in wrong format
  xmlhttp.open("GET","chkemail.html",true); xmlhttp.send();
  }
}
</script>

js文件与html文件放在同一文件夹中,html中部分代码如下:

<head>
... ...
<script type="txt/javascript" src="PrivateRegistration.js"></script>
</head>

<body>
... ...
<form name="form1" onSubmit="return chkform();" method="post" action="connectDataBase.jsp">
<table width="600" cellpadding="2" cellspacing="2" align="center" style="margin-left:60px">
  <tr>
  <td width="130"><span class="style1">* </span>Email</td>
  <td><input size=40 name="txtEmail" type="text" onKeyUp="chkEmail(this.value)" onBlur="chkEmail(this.value)"></td>
  <td><div id="email"></div></td>
  </tr>
... ...
<body>

现在js文件报错(dreamweaver cs5报错),没有任何提示。
只晓得是
  this.email=email;
这一行有问题(第一个function中的第一行),删掉之后又跳到下一行,删掉这个function之后跳到下一个function的第一行,如此循环
这样写有什么不对么?请各路大牛指教。

------解决方案--------------------
代码加上高亮很难吗?
HTML code
<script type="text/javascript">
var email;
var bemail="0"; // boolean value to check correctness
... ... // other parameters

function chkEmail(email){ // use AJax for dynamic checking
  this.email=email;
  var xmlhttp;
  if (window.XMLHttpRequest) {
  xmlhttp=new XMLHttpRequest();
  }
  else {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function() {  
  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
  document.getElementById("email").innerHTML=xmlhttp.responseText;
  }
  }
  if (/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(this.email)){ // regular expression checking
  bemail="1"; // to tell the web page the input is in right format
  xmlhttp.open("GET","chkemail.jsp?email="+email,true); xmlhttp.send();
  }
  else{
  bemail="0"; // to tell the web page the input is in wrong format
  xmlhttp.open("GET","chkemail.html",true); xmlhttp.send();
  }
}
</script>

js文件与html文件放在同一文件夹中,html中部分代码如下:

<head>
... ...
<script type="txt/javascript" src="PrivateRegistration.js"></script>
</head>

&l