jquery raidio buttion checked unchecked
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>
0
0
(请您对文章做出评价)
» 下一篇: 在word中如何把数字转化成人民币大写?
posted @ 2009-03-09 16:04 闫磊博客 阅读(1309) 评论(0) 编辑 收藏 所属分类: javascript
bad example
一个简单的例子,是懒宝宝让我帮忙的。因为我自己也注意到了,radio在选中后,一般无法取消,查了一下google,发现还是有方法 的。因此,立马解决了:
XML/HTML代码
< 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 > 因为用jquery的话,选中radion的方法很方便。所以,就尝试用这种方式解决了。。。但是用jquery无法取消checked状态,只能用原生js的方式才行(jquery是把元素都转换为对象,而不是DOM对象)查看更多关于jquery raidio buttion checked unchecked的详细内容...