简单的用户登录界面,遇到一个有关问题
简单的用户登录界面,遇到一个问题
为什么在判断用户名和密码是不是为空时,不能加上document.form.username==null???
------解决方案--------------------
没有用过js,不知道是不是应该判断 document.form.username==‘’
------解决方案--------------------
因为就算为空,value的值也为""(空字符串)。所以最简单,可用==""判断。
而且是document.form.username.value,而不是document.form.username,这是返回input的那个对象
为什么在判断用户名和密码是不是为空时,不能加上document.form.username==null???
js判断
------解决方案--------------------
没有用过js,不知道是不是应该判断 document.form.username==‘’
------解决方案--------------------
因为就算为空,value的值也为""(空字符串)。所以最简单,可用==""判断。
<script type="text/javascript">
function check(){
var name=document.form.username.value;
//if(name==null){
if(name==""){
alert("null");
}else{
alert("not null");
}
}
</script>
<form name="form">
<input type="text" name="username"/>
<input type="button" value="submit" onclick="check()"/>
</form>
而且是document.form.username.value,而不是document.form.username,这是返回input的那个对象