<?
xml version="1.0" encoding="gb2312"
?>
< user >
< name > 爱飞翔 </ name >
< password > 123 </ name >
< friendNum > 4 </ friendNum >
</ user >
< user >
< name > 爱飞翔 </ name >
< password > 123 </ name >
< friendNum > 4 </ friendNum >
</ user >
ex35.htm:(主要部分)
用户名:
<
INPUT
name
="username"
type
="text"
id
="username"
>
< P >
密码: < INPUT name ="password" type ="text" id ="password" >
</ P >
< P >
< INPUT type ="submit" name ="Submit" value ="提交" onClick ="checkUser()" >
</ P >
< XML ID ="userXML" SRC ="user.xml" ></ XML >
< SCRIPT language ="javascript" >
function checkUser()
{
var userNameNode=userXML.XMLDocument.documentElement.selectNodes("name");
var userNameR=userNameNode(0).firstChild.nodeValue;
var userPasswordNode=userXML.XMLDocument.documentElement.selectNodes("password");
var userPasswordR=userPasswordNode(0).firstChild.nodeValue;
var userFriendNode=userXML.XMLDocument.documentElement.selectNodes("friendNum");
var userFriendN=userFriendNode(0).firstChild.nodeValue;
if(username.value==userNameR&&password.value==userPasswordR)
{
alert("欢迎您,"+username.value+"!您的通讯录现在有"+friendNum.value+"位朋友");
location.href="ex35.xml";
}
else
{
alert("用户名和密码错误!");
clearName();
clearPassword();
}
}
</ SCRIPT >
< P >
密码: < INPUT name ="password" type ="text" id ="password" >
</ P >
< P >
< INPUT type ="submit" name ="Submit" value ="提交" onClick ="checkUser()" >
</ P >
< XML ID ="userXML" SRC ="user.xml" ></ XML >
< SCRIPT language ="javascript" >
function checkUser()
{
var userNameNode=userXML.XMLDocument.documentElement.selectNodes("name");
var userNameR=userNameNode(0).firstChild.nodeValue;
var userPasswordNode=userXML.XMLDocument.documentElement.selectNodes("password");
var userPasswordR=userPasswordNode(0).firstChild.nodeValue;
var userFriendNode=userXML.XMLDocument.documentElement.selectNodes("friendNum");
var userFriendN=userFriendNode(0).firstChild.nodeValue;
if(username.value==userNameR&&password.value==userPasswordR)
{
alert("欢迎您,"+username.value+"!您的通讯录现在有"+friendNum.value+"位朋友");
location.href="ex35.xml";
}
else
{
alert("用户名和密码错误!");
clearName();
clearPassword();
}
}
</ SCRIPT >
另外还有一个ex35.xml,用来显示结果.
上面我是书上写的,可是运行ex35.htm总是错误,说"userXML.XMLDocument.documentElement为空或不是对象".
请各位帮帮忙!