多个复选框的单击功能 [英] The click function for mutiple checkboxes

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

问题描述

我有很多复选框,都有不同的类名和ID名称。在这种情况下,如何为所有复选框设置常用的点击功能。

我尝试过使用

I have many checkboxes all with different class name and id name. In that case how can I have common click function for all checkboxes.
I have tried using

$("input[type='checkbox']").click(function (){
//some code
});



但仍然没有用。是否还有其他方法可以为所有复选框引用单击函数?


but still it is not working. Is there any other method other this to refer a click function for all checkboxes?

推荐答案

< span class =code-string> input [type ='checkbox'])。click( function (){
// 一些代码
});
("input[type='checkbox']").click(function (){ //some code });



但仍然没有用。还有其他任何方法来引用所有复选框的点击功能吗?


but still it is not working. Is there any other method other this to refer a click function for all checkboxes?


这是关于语法...你不需要周围的引号复选框 ...

但是有更简洁的方法:

It's about syntax...You need no the quotes around checkbox...
But there is a cleaner way to do it:


input:checkbox)。click(function(){
// 某些代码
});
("input:checkbox").click(function (){ //some code });



http://api.jquery.com/checkbox-selector/ [ ^ ]


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

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