good example
jquery check全选/取消全选
<HTML>
<HEAD>
<script type="text/javascript" src="jquery.js"></script>
<SCRIPT type="text/javascript">$(document).ready(function() {
$("#checkedAll").click(function(){
if($(this).attr("checked") == true){ //check all
$("input[@name='checkbox_name[]']").each(function(){
$(this).attr("checked",true);
});
}else{
$("input[@name='checkbox_name[]']").each(function(){
$(this).attr("checked",false);
});
}
});
});
</SCRIPT>
</HEAD>
<BODY>
<div class="components-list">
<input type="checkbox" name="checkbox_name[]" id="checkbox_name_1" />1<br />
<input type="checkbox" name="checkbox_name[]" id="checkbox_name_2" />2<br />
<input type="checkbox" name="checkbox_name[]" id="checkbox_name_3" />3<br />
<input type="checkbox" name="checkbox_name[]" id="checkbox_name_4" />4<br />
<input type="checkbox" name="checkedAll" id="checkedAll"/>全选/取消全选
</div>
<select id="test">
<option value="a">A</option>
<option value="b">B</option>
<option value="c" selected>C</option>
</select>
</BODY></HTML>
bad example
一个简单的例子,是懒宝宝让我帮忙的。因为我自己也注意到了,radio在选中后,一般无法取消,查了一下google,发现还是有方法 的。因此,立马解决了:
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
- <table class="rs" border="0" cellspacing="0" cellpadding="0">
- <tr>
- <td>HIV :阴
- <input type="radio" name="hiv[0]" value="HIV:阴" union="yin"/>
- 阳
- <input type="radio" name="hiv[0]" value="HIV:阳" union="yang" /></td>
- <td>梅毒:阴
- <input type="radio" name="hiv[1]" value="梅毒:阴" union="yin" />
- 阳
- <input type="radio" name="hiv[1]" value="梅毒:阳" union="yang" /></td>
- <td>疱疹:阴
- <input type="radio" name="hiv[2]" value="疱疹:阴" union="yin" />
- 阳
- <input type="radio" name="hiv[2]" value="疱疹:阳" union="yang" /></td>
- <td>淋病:阴
- <input type="radio" name="hiv[3]" value="淋病:阴" union="yin" />
- 阳
- <input type="radio" name="hiv[3]" value="淋病:阳" union="yang" /></td>
- </tr>
- <tr>
- <td>非淋:阴
- <input type="radio" name="hiv[4]" value="非淋:阴" union="yin" />
- 阳
- <input type="radio" name="hiv[4]" value="非淋:阳" union="yang" /></td>
- <td>湿疣:阴
- <input type="radio" name="hiv[5]" value="湿疣:阴" union="yin" />
- 阳
- <input type="radio" name="hiv[5]" value="湿疣:阳" union="yang" /></td>
- <td>丙肝:阴
- <input type="radio" name="hiv[6]" value="丙肝:阴" union="yin" />
- 阳
- <input type="radio" name="hiv[6]" value="丙肝:阳" union="yang" /></td>
- <td><a style="cursor:pointer;" id='allyin'>全阴</a> <a style="cursor:pointer;" id='allyang'>全阳</a> <a id='allempty' style="cursor:pointer;">重填</a>
- <script>
- $(function(){
- $('#allyin').click(function(){
- $(':input[union="yin"]').attr('checked','checked');
- });
- $('#allyang').click(function(){
- $(':input[union=yang]').attr('checked','checked');
- });
- $('#allempty').click(function(){
- $(':input[union=yang]').each(function(){
- $(this).attr('checked','checked');
- var tmp = $(this)[0];
- tmp.checked = false;
- tmp = null;
- })
- });
- });
- </script></td>
- </tr>
- </table>