问题描述
我正在这样的项目中,我有这样的 fieldset #a .
<fieldset id="a">
<input type="checkbox" name="c1" value="v1" checked="checked" />
<input type="checkbox" name="c2" value="v2"/>
<input type="checkbox" name="c3" value="v3"/>
</fieldset>
此字段集#a 复选框:已选中值为动态.
我在同一页面上还有另一个字段集#b .
我想要的是在页面加载时从 fieldset #a到fieldset #b Serially 分配/复制复选框:已选中值. [两个字段集都有相同数量的复选框. ]
<fieldset id="b">
<input type="checkbox" name="cc1" value="vv1"/>
<input type="checkbox" name="cc2" value="vv2"/>
<input type="checkbox" name="cc3" value="vv3"/>
</fieldset>
我该如何实现?谢谢.
您可以使用您提到的选择器来执行此操作,然后循环使用每个值,获取它们的索引并根据这些标记更新下一个字段集复选框. /p>
赞:
$('fieldset#a input[type="checkbox"]:checked').each(function(){
$('fieldset#b input[type="checkbox"]').eq($(this).index()).prop('checked',true);
});
示例: http://jsfiddle.net/niklasvh/hHnLu/
I'm working on project where I have fieldset #a like this.
<fieldset id="a">
<input type="checkbox" name="c1" value="v1" checked="checked" />
<input type="checkbox" name="c2" value="v2"/>
<input type="checkbox" name="c3" value="v3"/>
</fieldset>
This fieldset #a checkbox : is checked value is Dynamic.
I have another fieldset #b on the same page.
What I want is to Assign/Copy checkbox : is checked value from fieldset #a to fieldset #b Serially on page load. [ Both fieldset have equal number of checkboxes. ]
<fieldset id="b">
<input type="checkbox" name="cc1" value="vv1"/>
<input type="checkbox" name="cc2" value="vv2"/>
<input type="checkbox" name="cc3" value="vv3"/>
</fieldset>
How can I achieve this ? Thanks.
You could do it using that selector you mentioned and then looping each of the values, getting their index, and updating the next fieldsets checkboxes according to those indicies.
Like this:
$('fieldset#a input[type="checkbox"]:checked').each(function(){
$('fieldset#b input[type="checkbox"]').eq($(this).index()).prop('checked',true);
});
example: http://jsfiddle.net/niklasvh/hHnLu/
这篇关于将一组复选框的检查状态复制到另一个字段集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!