jquery问题求解决 jquery导航 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $(document).ready(function(){ $('.error').hide(); $('.submit').click(function(event){ var count=$('input:checked').length; var amt=0; if(count==0){ $('p .result').hide(); $('.error').show(); }else{ $('form').find(':checkbox').each(funtion(){ if($(this).is(':checked')){ amt=amt+parseInt($(this).val()); } }); $('.error').hide(); $('p .result').show(); $('p .result').text('you bill is $'+amt); } event.preventDefault(); });});<html><head> <title>检查复选框是否被选中</title> <link rel="stylesheet" type="text/css" href="demo3.css" /> <script type="text/javascript" src="../jQuery1.8.3.js"></script> <script type="text/javascript" src="demo3.js"></script></head><body> <form> <input type="checkbox" name="pizza" value=5 class="infobox" />pizza $5<br /> <input type="checkbox" name="hotdog" value=2 class="infobox" />hotdog $2<br /> <input type="checkbox" name="coke" value=3 class="infobox" />coke $3<br /> <input type="checkbox" name="fries" value=6 class="infobox" />french fries $6<br /> <p class="error">至少选择一个复选框</p> <p class="result"></p> <input type="submit" class="submit" value="submit" /> </form></body></html>.infobox{margin-top:15px;}.submit{width:100px; height:30px; margin-left:150px; margin-top:10px;}.error{color:red;} $(document).ready(function(){ $('.error').hide();$('.result').hide(); $('.submit').click(function(event){ var count=$('input:checked').length; var amt=0; if(count==0){ $('p .result').hide(); $('.error').show(); }else{ $('form').find(':checkbox').each(function(){ if($(this).is(':checked')){ amt=amt+parseInt($(this).val()); } }); $('.error').hide(); $('.result').show(); $('.result').html('you bill is $'+amt); } event.preventDefault();return false; });}); return false 一下即可 就像楼上那样 无全局变量,怎么获取父function中的变量$a? 怎么隐藏label 大侠们,问个问题,急! 关于mysql_fetch_array指针 请给小弟指点一下 ice_berg16(寻梦的稻草人) 兄弟进来,有事请请教,其它高人也可以进来~~~~~~ 如何定义私有函数 PHP安装要什么条件? 我从数据库里读出的数据在WEB上显示是乱的,看不懂,好像要解码,但不知道怎么作,请各位大哥,大姐帮忙。 LINUX和APACHE的问题?? php无法打开pdo_odbc问题 怎么使用php制作一个课程(课程任选)教学资源网站
$('.error').hide();
$('.submit').click(function(event){
var count=$('input:checked').length;
var amt=0;
if(count==0){
$('p .result').hide();
$('.error').show();
}else{
$('form').find(':checkbox').each(funtion(){
if($(this).is(':checked')){
amt=amt+parseInt($(this).val());
}
});
$('.error').hide();
$('p .result').show();
$('p .result').text('you bill is $'+amt);
}
event.preventDefault();
});
});
<html>
<head>
<title>检查复选框是否被选中</title>
<link rel="stylesheet" type="text/css" href="demo3.css" />
<script type="text/javascript" src="../jQuery1.8.3.js"></script>
<script type="text/javascript" src="demo3.js"></script>
</head>
<body>
<form>
<input type="checkbox" name="pizza" value=5 class="infobox" />pizza $5<br />
<input type="checkbox" name="hotdog" value=2 class="infobox" />hotdog $2<br />
<input type="checkbox" name="coke" value=3 class="infobox" />coke $3<br />
<input type="checkbox" name="fries" value=6 class="infobox" />french fries $6<br />
<p class="error">至少选择一个复选框</p>
<p class="result"></p>
<input type="submit" class="submit" value="submit" />
</form>
</body>
</html>.infobox{margin-top:15px;}
.submit{width:100px; height:30px; margin-left:150px; margin-top:10px;}
.error{color:red;}
$('.error').hide();
$('.result').hide(); $('.submit').click(function(event){
var count=$('input:checked').length;
var amt=0;
if(count==0){
$('p .result').hide();
$('.error').show();
}else{
$('form').find(':checkbox').each(function(){
if($(this).is(':checked')){
amt=amt+parseInt($(this).val());
}
});
$('.error').hide();
$('.result').show();
$('.result').html('you bill is $'+amt);
}
event.preventDefault();
return false;
});
});