首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

html导入独立的js文件出错,无法调用function,求教!该怎么解决

2012-05-16 
html导入独立的js文件出错,无法调用function,求教!js文件代码如下:script typetext/javascriptvar em

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 parametersfunction 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的文件时,是不需要加<script>与结尾的</script>的。
[解决办法]
<script type="txt/javascript" src="PrivateRegistration.js"></script>
->
<script type="text/javascript" src="PrivateRegistration.js"></script>

热点排行