小弟写了一个登陆框,js文件统一保存在一个文件夹中,但点击按钮进行处理的时候却没有什么反映?请问这是为啥?<!DOCTYPE script PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
<link rel="stylesheet" href="CSS/style.css" type="text/css" />
<script language="text/javascript" src="./js/ajaxLoad.js"></script>
<title>登陆</title>
</head>
<body>
<div>
<form name="user_login">
<table style="font:0.8em Arial,幼圆,sans-serif;width:640px;height:25px"><tr>
<td style="width:35%"><label>用户名:</label> <input type="text" name="user_name" style="width:150px"></input></td>
<td style="width:32%"><label>密码:</label><input type="password" name="user_password" style="width:150px"></input></td>
<td style="width:15%">
<label>个人</label><input type="radio" name="utype" value="1" checked="checked"></input>
<label>企业</label><input type="radio" name="utype" value="0"></input>
</td>
<td style="width:8%"><input type="button" value="登陆" onclick ="userLogin(user_name.value,user_password.value)"></input></td>
<td>
<a>退出</a>
<a href="ulogin.php">注册</a>
</td>
</tr></table>
</form>
</div></body></html>ajaxLoad.js 文件内容val xmlHttp;function userLogin(u_name,u_password){
if(user_login.user_name.value == "" ){
alert("--请输入用户名!");
user_login.user_name.focus();
return;
}
else if(user_login.user_password.value == ""){
alert("--请输入密码!");
user_login.user_password.focus();
return;
}
else {
xmlHttp = getXmlHttpObject();
if(xmlHttp == null){
alert("---该浏览器不支持ajax.......");
return;
}
else{
var url = "loginCheck.php";
url = url + "?n=" + u_name + "&p=" + u_password ;
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
}
}
function getXmlHttpObject(){
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e){
// Internet Explorer
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("您的浏览器不支持AJAX!");
return false;
}
}
}
return xmlHttp;
}function stateChanged(){
if(xmlHttp.readyState != 4 ){
document.getElementById("user_info").innerHTML="正在验证用户数据,请稍后...";
}
if(xmlHttp.readyState == 4 ){
document.getElementById("user_info").innerHTML=xmlHttp.responseText;
}
}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
<link rel="stylesheet" href="CSS/style.css" type="text/css" />
<script language="text/javascript" src="./js/ajaxLoad.js"></script>
<title>登陆</title>
</head>
<body>
<div>
<form name="user_login">
<table style="font:0.8em Arial,幼圆,sans-serif;width:640px;height:25px"><tr>
<td style="width:35%"><label>用户名:</label> <input type="text" name="user_name" style="width:150px"></input></td>
<td style="width:32%"><label>密码:</label><input type="password" name="user_password" style="width:150px"></input></td>
<td style="width:15%">
<label>个人</label><input type="radio" name="utype" value="1" checked="checked"></input>
<label>企业</label><input type="radio" name="utype" value="0"></input>
</td>
<td style="width:8%"><input type="button" value="登陆" onclick ="userLogin(user_name.value,user_password.value)"></input></td>
<td>
<a>退出</a>
<a href="ulogin.php">注册</a>
</td>
</tr></table>
</form>
</div></body></html>ajaxLoad.js 文件内容val xmlHttp;function userLogin(u_name,u_password){
if(user_login.user_name.value == "" ){
alert("--请输入用户名!");
user_login.user_name.focus();
return;
}
else if(user_login.user_password.value == ""){
alert("--请输入密码!");
user_login.user_password.focus();
return;
}
else {
xmlHttp = getXmlHttpObject();
if(xmlHttp == null){
alert("---该浏览器不支持ajax.......");
return;
}
else{
var url = "loginCheck.php";
url = url + "?n=" + u_name + "&p=" + u_password ;
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
}
}
function getXmlHttpObject(){
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e){
// Internet Explorer
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("您的浏览器不支持AJAX!");
return false;
}
}
}
return xmlHttp;
}function stateChanged(){
if(xmlHttp.readyState != 4 ){
document.getElementById("user_info").innerHTML="正在验证用户数据,请稍后...";
}
if(xmlHttp.readyState == 4 ){
document.getElementById("user_info").innerHTML=xmlHttp.responseText;
}
}
顺便说下
<input type="radio" ></input>是单标签 ~
单独一个js文件很src属性指向文件路径。
你的JS文件夹和本页是什么路径关系?
如果是同级,引用路径是src="js/ajaxLoad.js"
如果包含本页的文件夹和JS文件夹同级,,引用路径是src="../js/ajaxLoad.js"以此类推,自己检查一下吧
把<script language="text/javascript" src="./js/ajaxLoad.js"></script>
改为:<script type="text/javascript" src="./js/ajaxLoad.js"></script>