在jQuery中是否有类似于对复选框启用事件的on(‘click’)方法?

huangapple go评论73阅读模式
英文:

In jQuery is there any method similar to on('click' for checkbox enabled event?

问题

我有用于排序目的的升序和降序排序图标。在初始加载时,排序处于启用状态。
我需要类似以下的解决方案:

$('.pgggo-container-ajax-sorting').on('click', '.pgggocheckboxdecendinp', function(event) {

当点击降序图标时,应该运行此函数。但是上述方法对复选框无效。请帮忙。

英文:

I have accending and descending sort icons for sorting purposes. On the initial loading, sorting is in an enabled condition
I am in need of a solution similar to below:

$('.pgggo-container-ajax-sorting').on('click', '.pgggocheckboxdecendinp', function(event) {

say when the descend icon is clicked this function should run. But the above method is not working for a checkbox. Please help

答案1

得分: 1

你可以尝试这样做:

$('.pgggo-container-ajax-sorting').on('click', '.pgggocheckboxdecendinp', function(event) {
  if($(this).is(':checked')) {
    // 选中状态的代码
  }
  else {
    // 未选中状态的代码
  }
});

这将适用于复选框。

英文:

You can try this:

$('.pgggo-container-ajax-sorting').on('click', '.pgggocheckboxdecendinp', function(event) {
  if($(this).is(':checked')) {
    //  code for checked condition
  }
  else {
    //  code for unchecked condition
  }
});

This will work with checkbox.

huangapple
  • 本文由 发表于 2020年1月3日 18:25:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/59576892.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定