日期:2014-05-16  浏览次数:20395 次

简单javascript问题 在线等
我想用Javascript判断用户名输入是否为空。
为什么用记事本保存为html文件打开时,会出现网页错误的现象。
<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN ">
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=UTF-8 ">
<title> Insert   title   here </title>
<script   type= "text/javascript "   language= "javascript ">
        function   userCheck(){
        var   f=document.form1;
        var   username=f.username.value;
        if(username= " "){
        window.alert( "用户名不能为空! ")
        f.username.focus();
        return   false;
        }
        else
        {
        //send_request( 'check.jsp?username '=+username);
        }
        }
        }
</script>  

</head>
<body> <form   method= "post "   name= "form1 ">
<p> &nbsp;&#29992;&#25143;&#21517;&#65306;
<input   type= "text "   name= "username ">
<input   type= "button "   value= "唯一性检查 "   name= "check "   onclick= "userCheck() ">
<input   type= "button "   value= "提交 "   name= "submit ">  
</p> <p> &nbsp; </p> <p> &nbsp; </p> <p> &nbsp; </p> <p> &nbsp; </p> </form>

</body>
</html>


------解决方案--------------------
晕,你滴大括号不匹配!!!

删除第 20 滴大括号!!!

<script type= "text/javascript " language= "javascript ">
function userCheck(){
var f=document.form1;
var username=f.username.value;
if(username= " "){
window.alert( "用户名不能为空! ")
f.username.focus();
return false;
}
else
{
//send_request( 'check.jsp?username '=+username);
}
}
//} 删除它~~~,哈
</script>
------解决方案--------------------
if(username= " "){
js判断相等用==
if(username== " "){