复制复选框标记到另一个表单 [英] copy checkboxes marks to another form

查看:146
本文介绍了复制复选框标记到另一个表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种表单:

foo:

<form id="foo_form" method="post" action="foo">
  <input class="foo checkbox" id="foo_select_1" name="ids[]" type="checkbox" value="1" />
  <input class="foo checkbox" id="foo_select_2" name="ids[]" type="checkbox" value="2" />
  <input class="foo checkbox" id="foo_select_3" name="ids[]" type="checkbox" value="3" />
  ...
  <input type="submit" value="action 1" />
</form>

bar

<form id="bar_form" method="post" action="bar">
  <input class="bar checkbox" id="bar_select_1" name="ids[]" type="checkbox" value="1" />
  <input class="bar checkbox" id="bar_select_2" name="ids[]" type="checkbox" value="2" />
  <input class="bar checkbox" id="bar_select_3" name="ids[]" type="checkbox" value="3" />
  ...
  # some other input fileds here
  <input type="submit" value="action 2" />
</form>

我需要JS(jQuery),每次更改的复选框foo 将更改 bar 下的相应复选框。

I need JS (jQuery) that for every change of checkbox at foo will change corresponding checkbox at bar.

针对相同复选框的不同操作。我想用CSS隐藏 bar ,并且只让提交按钮可见。全部在此处中进行了说明。

The main goal for that is to have 2 different actions for the same checkboxes. I want to hide those at bar with CSS and leave only submit button visible. All is described here

推荐答案

这样做:

小提琴

Fiddle

$(document).ready(function(){
    $('#foo_form input:checkbox').change(function(){
       $('#bar_' + this.id.replace('foo_', '')).prop('checked', this.checked); 
    });
});

这篇关于复制复选框标记到另一个表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆