jquery 判断表单是否为空

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<script type="text/javascript">
$(document).ready(function(){
$("uname").keydown(function(){
$("namenull").css("dispaly","none");
});
$("upwd").keydown(function(){
$("pwdnull").css("dispaly","none");
});
});
</script>
<script type="text/javascript">
function login(){
if($("#uname").value=="") {
$("#namenull").css("dispaly","block");
$("#uname").focus();
return false;
}else if ($("#upwd").value=="") {
$("#pwdnull").css("dispaly","block");
$("#upwd").focus();
return false;
}
return true;
}
</script>
</head>
<body>
<div>
<button data-toggle="modal" data-target="#login">登录</button>
</div>
<div class="modal fade" id="login" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<form action="index.html" method="post" name="form1" onsubmit="return login()">
<label>用户名</label>
<input type="text" name="uname" id="uname">
<label style="display:none;color:red;" id="namenull">请输入用户名!</label>
<label>密码</label>
<input type="text" name="upwd" id="upwd">
<label style="display:none;color:red;" id="pwdnull">请输入密码!</label>
<input type="submit" value="登录">
</form>
</div>
</div>
</div>
</div>
</body>
</html>

想知道这么写的问题在哪里?
一直无法实现

参考下面代码中的if判断来实现的,如果真空怎么样,如果不为空怎么样:

$(document).ready(function() {

$(“form”).submit(function(){

if ($(“select[name='boardid']“).val() == â€œâ€){

alert(“对不起,请选择类别!”);

$(“select[name='boardid']“).focus();

return false;

}

if ($(“select[name='boardid']“).val() == â€œè¯·é€‰æ‹©åˆ†ç±»â€){

alert(“对不起,请选择类别!”);

$(“select[name='boardid']“).focus();

return false;

}

if ($(“input[name='txtcontent']“).val() == â€œâ€){

alert(“对不起,请填写内容!”)

$(“input[name='txtcontent']“).focus();

return false

}

if ($(“input[name='txtcontent']“).val().length > 150){

alert(“对不起,内容超过150个字符限制!”)

$(“input[name='txtcontent']“).focus();

return false

}})

$(“#t”).keyup(function(){

$(“.inner”).text($(“input[name='txtcontent']“).val());

}).change(function(){

$(“.inner”).text($(“input[name='txtcontent']“).val());

});

});
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-05-09
if($("#uname").value=="")

改为
if($("#uname").val()=="")

还有很多jquery的调用语法错了,建议参考一下jquery的取值方法追问

谢谢!!!
已全部搞定

感觉自己的基本功还是不行。。。

追答

忘记给分我啦T_T

本回答被提问者和网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网