开发者

JQuery function "On tick" (Not "On click")

Is there any way in JQUERY to trigger a function when a checkbox has been ticked or unticked?

NOTE: I dont want the "click" function because I use another buttons to tick or untick 20 checkboxes at the same time for example. (and in that case I have only 1 click, but really I need to do the "click" function 20 times, one per each 20 checkbox ticked) I don't want make loops because I'm using pagination and another stuff, I'm looking for something more simple as a "onTick" function.

The event is onTick or onUnTick but not "onClick"

I开发者_如何学Gos there any solution?

Many thanks!

Solved and 100% working:

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


$('input[type=checkbox]').bind('change', function(e){
  var jT = $(this);  //jT is a jQuery Object for the current input
    //I.E. 20 'ticks' = 20 calls no looping needed.
  if (jT.is(':checked')){
    //was checked
  } else {
    //was unchecked
  }
});


I'm thinking maybe onChange would work.


Try the onchange event. It's fired when the state of the checkbox changes (even programaticaly).


jQuery has a .change() method that basically handles the onChange event. You can probably use that. http://api.jquery.com/change/


This is what I did to fade out an item when I clicked my checkbox.

$(".done").live("click", function(){

if ($(this).is(':checked')) {

$(this).parent().fadeTo('slow', 0.5); }else{

$(this).parent().fadeTo('slow', 1); } });

.done is my checkbox class, to do this for the multiple checkboxes you would set it to your select all. Ex.

$(".selectall").live("click", function(){

if ($(this).is(':checked')) {

$(this).parent().fadeTo('slow', 0.5); }else{

$(this).parent().fadeTo('slow', 1); } });

So essentially .is(':checked')) will do what you want.

Edit: Sorry about the code fail - Something went wrong.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜