脚本宝典收集整理的这篇文章主要介绍了javascript代码实例教程-一天一个js(3)多选框简单操作,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。
[htML]
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<script src="https://ajax.GOOGLEapis.COM/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$(".put1").click(function(){
$(":checkbox").attr("checked","checked");
});
$(".put2").click(function(){
$(":checkbox").each(function(){
if($(this).is(":checked")){
$(this).removeAttr("checked");
}else{
$(this).attr("checked","checked");
};
});
});
$(".put3").click(function(){
VAR count = $(":checkbox:checked").length;
var sum = "";
$(":checkbox:checked").each(function(){
var array = $(this).siblings("label").text();
for(i=0;i<array.length;i++){
sum = sum+array[i];
};
});
$("h4").text(sum).siblings("h3").text("您总共选择了"+count+"个,分别是:");
});
});
</script>
<style type="text/css">
p { width:800px; padding:10px; border:1px solid #000; margin:200px auto;}
h3 { color:#900;}
</style>
<tITle>多选框简单操作</title>
</head>
<body>
<p>
<p><label for="c1">1.苹果</label><input id="c1" type="checkbox" /></p>
<p><label for="c2">2.香蕉</label><input id="c2" type="checkbox" /></p>
<p><label for="c3">3.橘子</label><input id="c3" type="checkbox" /></p>
<p><label for="c4">4.菠萝</label><input id="c4" type="checkbox" /></p>
<p><label for="c5">5.西瓜</label><input id="c5" type="checkbox" /></p>
<p><label for="c6">6.橙子</label><input id="c6" type="checkbox" /></p>
<p><label for="c7">7.鸭梨</label><input id="c7" type="checkbox" /></p>
<p><label for="c8">8.柚子</label><input id="c8" type="checkbox" /></p>
<p><label for="c9">9.葡萄</label><input id="c9" type="checkbox" /></p>
<p><input type="button" class="put1" value="全选" />
<input type="button" class="put2" value="反选" />
<input type="button" class="put3" value="显示我选择的" /></p>
<h3></h3><h4></h4>
</p>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$(".put1").click(function(){
$(":checkbox").attr("checked","checked");
});
$(".put2").click(function(){
$(":checkbox").each(function(){
if($(this).is(":checked")){
$(this).removeAttr("checked");
}else{
$(this).attr("checked","checked");
};
});
});
$(".put3").click(function(){
var count = $(":checkbox:checked").length;
var sum = "";
$(":checkbox:checked").each(function(){
var array = $(this).siblings("label").text();
for(i=0;i<array.length;i++){
sum = sum+array[i];
};
});
$("h4").text(sum).siblings("h3").text("您总共选择了"+count+"个,分别是:");
});
});
</script>
<style type="text/css">
p { width:800px; padding:10px; border:1px solid #000; margin:200px auto;}
h3 { color:#900;}
</style>
<title>多选框简单操作</title>
</head>
<body>
<p>
<p><label for="c1">1.苹果</label><input id="c1" type="checkbox" /></p>
<p><label for="c2">2.香蕉</label><input id="c2" type="checkbox" /></p>
<p><label for="c3">3.橘子</label><input id="c3" type="checkbox" /></p>
<p><label for="c4">4.菠萝</label><input id="c4" type="checkbox" /></p>
<p><label for="c5">5.西瓜</label><input id="c5" type="checkbox" /></p>
<p><label for="c6">6.橙子</label><input id="c6" type="checkbox" /></p>
<p><label for="c7">7.鸭梨</label><input id="c7" type="checkbox" /></p>
<p><label for="c8">8.柚子</label><input id="c8" type="checkbox" /></p>
<p><label for="c9">9.葡萄</label><input id="c9" type="checkbox" /></p>
<p><input type="button" class="put1" value="全选" />
<input type="button" class="put2" value="反选" />
<input type="button" class="put3" value="显示我选择的" /></p>
<h3></h3><h4></h4>
</p>
</body>
</html>
觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! js脚本,巧夺天工,精雕玉琢。小宝典献丑了!
以上是脚本宝典为你收集整理的javascript代码实例教程-一天一个js(3)多选框简单操作全部内容,希望文章能够帮你解决javascript代码实例教程-一天一个js(3)多选框简单操作所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。