[html]
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://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">
div { width:800px; padding:10px; border:1px solid #000; margin:200px auto;}
h3 { color:#900;}
</style>
<title>多選框簡單操作</title>
</head>
<body>
<div>
<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>
</div>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://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">
div { width:800px; padding:10px; border:1px solid #000; margin:200px auto;}
h3 { color:#900;}
</style>
<title>多選框簡單操作</title>
</head>
<body>
<div>
<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>
</div>
</body>
</html>