JQuery_checkbox_使用小结

来源:互联网 发布:淘宝用户被冻结怎么办 编辑:程序博客网 时间:2024/06/04 18:17

html:

<ul><li style="float:left;margin-right: 25px;"><input style="width:15px;height:15px;float:left;" type="checkbox" name="yq_channnel" value="1" checked="checked"><span style="float:left;display:block;margin-top:2px;">突发事件</span></li><li style="float:left;margin-right: 25px;"><input style="width:15px;height:15px;float:left;" type="checkbox" name="yq_channnel" value="4" checked="checked"><span style="float:left;display:block;margin-top:2px;">防总成员</span></li><li style="float:left;margin-right: 25px;"><input style="width:15px;height:15px;float:left;" type="checkbox" name="yq_channnel" value="3" checked="checked"><span style="float:left;display:block;margin-top:2px;">地方报道</span></li><li style="float:left;margin-right: 25px;"><input style="width:15px;height:15px;float:left;" type="checkbox" name="yq_channnel" value="5"><span style="float:left;display:block;margin-top:2px;">山洪灾害</span></li><li style="float:left;margin-right: 25px;"><input style="width:15px;height:15px;float:left;" type="checkbox" name="yq_channnel" value="7"><span style="float:left;display:block;margin-top:2px;">干旱缺水</span></li><li style="float:left;margin-right: 25px;"><input style="width:15px;height:15px;float:left;" type="checkbox" name="yq_channnel" value="11" checked="checked"><span style="float:left;display:block;margin-top:2px;">论坛信息</span></li><li style="float:left;margin-right: 25px;"><input style="width:15px;height:15px;float:left;" type="checkbox" name="yq_channnel" value="10"><span style="float:left;display:block;margin-top:2px;">世界水旱灾害</span></li><li style="float:left;margin-right: 25px;"><input style="width:15px;height:15px;float:left;" type="checkbox" name="yq_channnel" value="9"><span style="float:left;display:block;margin-top:2px;">台风灾害</span></li><li style="float:left;margin-right: 25px;"><input style="width:15px;height:15px;float:left;" type="checkbox" name="yq_channnel" value="8"><span style="float:left;display:block;margin-top:2px;">工程险情</span></li><li style="float:left;margin-right: 25px;"><input style="width:15px;height:15px;float:left;" type="checkbox" name="yq_channnel" value="6"><span style="float:left;display:block;margin-top:2px;">江河洪水</span></li></ul>

JQuery:

获取checkbox选中的val值:

var typeStr = '';$("input[name^='yq_channnel']").each(function(){if(this.checked){typeStr = typeStr + $(this).val() + ",";}});

给相同name值的checkbox绑定click事件:

$("input[name='yq_channnel']").click(function (){getYuQingInfo();});

给指定value值添加选中状态:

$("input:checkbox[value='"+arr+"']").attr('checked','true');



原创粉丝点击