简体   繁体   English

确定单击了哪个复选框

[英]Determine which checkbox is been clicked

I've chosen Ember.js for one my project and this is the first time I'm fiddling with this framework. 我为我的一个项目选择了Ember.js,这是我第一次熟悉这个框架。 Currently, I'm trying to get my mind around the framework and I'm stuck at one particular problem. 目前,我试图让我对框架有所了解,但我陷入了一个特定的问题。

I've scenario where the user will be given a list of checkboxes to mark the give item and I've to trigger an ajax call after determining which checkbox has been checked. 我设想的情况是,将为用户提供一系列复选框以标记赠予项目,并且在确定已选中哪个复选框后必须触发ajax调用。 List of checkboxes is been fetched on demand from the server and they may vary per item. 复选框列表是根据需要从服务器获取的,每个项目可能有所不同。

My question is how do I determine which checkbox is been clicked by the user, so that I will be able to make an ajax call? 我的问题是如何确定用户单击了哪个复选框,以便能够进行ajax调用?

http://emberjs.jsbin.com/miferefivu/1/ http://emberjs.jsbin.com/miferefivu/1/

What you can do using a bit of jQuery is if your checkboxes can share either a common prefix on their id or a common class. 您可以使用一些jQuery做的是,如果您的复选框可以在其ID或公共类上共享一个公共前缀。 You can add the event like so for each case: 您可以为每种情况添加事件,如下所示:

$(".checkboxclass").click(function(e) {     
    console.log($(this).prop("id"));
});

$("input[id^='checkbox-']").click(function(e) {          
    console.log($(this).prop("id"));
});

You can then either by checking the checkbox's value or id determine which checkbox has been ticked 然后,您可以通过选中复选框的值或ID来确定已选中哪个复选框

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

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