js文件代码如下:<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文件报错(dreamweaver cs5报错),没有任何提示。
只晓得是
this.email=email;
这一行有问题(第一个function中的第一行),删掉之后又跳到下一行,删掉这个function之后跳到下一个function的第一行,如此循环
这样写有什么不对么?请各路大牛指教。
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文件报错(dreamweaver cs5报错),没有任何提示。
只晓得是
this.email=email;
这一行有问题(第一个function中的第一行),删掉之后又跳到下一行,删掉这个function之后跳到下一个function的第一行,如此循环
这样写有什么不对么?请各路大牛指教。
<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>
->
<script type="text/javascript" src="PrivateRegistration.js"></script>
没问题,以前js放在html里面没有独立出来的时候一切都可以运行,没有任何问题,所以jsp这边是没错的。
同时也感谢t5500的热心帮忙!