求助 很纠结的问题
这是我按照书上写的代码
结果老是提示错误
错误代码如下
SCRIPT5007: Unable to get value of the property 'passname2': object is null or undefined
然后源代码如下
<html>
<title>右键菜单</title>
<head>
<script language="JavaScript">
function trim(str){
var t=str.replace(/(^\s*)|(\s*$)/g,""); //用正则表达式将前后空格用空字符串替代
return t.replace(/(^ *)|( *$)/g,"");
}
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}
}
function validate(){
createXMLHttpRequest();
var name=document.getElementById("username").value;
var pass=document.getElementById("passname").value;
var mailname=document.getElementById("mailname").value;
var str="name="+name+"&pass="+pass+"&mailname="+mailname;
var url="zhuce1.jsp";
xmlHttp.open("POST",url,true);
xmlHttp.onreadystatechange=callback;
xmlHttp.setRequestHeader("Contetn-Type","aplication/x-www-form-urlencoded");
xmlHttp.send(str);
}
function callback(){
if(xmlHttp.readyState==4){
var s=xmlHttp.responseText;
if(trim(s)==1){
alert("用户注成功,即将转向首页");
clear();
}
if(trim(s)==2){
var ta="<font color='red'>该名称在数据库中已存在,请重新输入</font>"
document.getElementById("res").innerHTML=ta;
document.getElementById("username").value="";
}
}
}
function clear(){
document.getElementById("username").value="";
document.getElementById("passname").value="";
document.getElementById("passname2").value="";
document.getElementById("mailname").value="";
}
function checkPassword(e){
var ok="1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_.-";
for(var i=0;i<e.length;i++){
if(ok.indexOf(e.charAt(i))<0){
return false;
}
}
return true;
}
function checkEmail(e){
var ok="1234567890qwertyuiopasdfghjklzxcvbnm[].+@-_QWERTYUIOPASDFGHJKLZXCVBNM";
for(var i=0;i<e.length;i++){
if(ok.indexOf(e.charAt(i))<0){
return false;
}
}
if(e.indexOf("@")<=0){
return false;
}
if(e.indexOf(".")<=0){
return false;
}
if(e.indexOf("@")>e.lastIndexOf(".")){
return false;
}
return true;
}
function validate_form(){
if(document.form1.username.value==""){
alert("昵称不能为空!");
return false;
}
if(bytelength(document.form1.username.value)<1||bytelength(document.form1.username.value)>20){
alert("您输入的昵称不合法!");
return false;
}
if(document.form1.passname.value==""){
&