简体   繁体   English

jQuery onclick更改父背景

[英]jQuery onclick change parent background

I downloaded the script from emposha.com/javascript/fcbklistselection-like-facebook-friends-selector.html and made a few modifications, as the source wasn't working as required (When submitting the form, all of the values were being sent to the php handler, not just the checked ones). 我从emposha.com/javascript/fcbklistselection-like-facebook-friends-selector.html下载了脚本并进行了一些修改,因为源未按要求工作(提交表单时,所有值都已发送到php处理程序,而不仅仅是已检查的)。

My working example is in this Demo . 我的工作示例在此Demo中

My issue is this: how can I check a group of <lis> so that I could have a 'Select All' button? 我的问题是:如何检查一组<lis>以便可以使用“全选”按钮?

You can do it like this: 您可以这样做:

$("#fcbklist li input:checkbox").attr("checked", true);

Or if you want a toggle on that select all box that checks when it's checked, unchecks all when it's not, do this: 或者,如果您希望在选中该复选框的全选框上进行切换,如果未选中,则取消选中所有框,请执行以下操作:

$("#selectAll").change(function() {
  $("#fcbklist li input:checkbox").attr("checked", this.checked);
});

To get the effect you want with the plugin though, you'll need to fire a click on the parent as well, like this: 为了获得想要的效果,您还需要在父级上click ,如下所示:

$("#selectAll").change(function() {
  $("#fcbklist li input:checkbox").attr("checked",this.checked).parent().click();
});    ​

You can try a working sample here . 您可以在这里尝试工作示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM