【问题标题】:is there another way I can fire my js function instead of using .change有没有另一种方法可以触发我的 js 函数而不是使用 .change
【发布时间】:2013-08-14 23:09:08
【问题描述】:

我有这个函数,它在选中/取消选中复选框时调用其他一些函数:

 $page = $(event.target);

 $page.find(".checkboxes").change(function () {
     if (this.checked) {
        checked(this);
     } else {
        unchecked();
    }
 });

但是,这在 IE 8 中似乎不起作用(Internet Explorer 8 似乎两次调用了我的选中/未选中函数)。是否有另一个事件我可以调用一个复选框来更好地触发这些东西?

【问题讨论】:

  • 因为$page$(event.target) 我想您显示的整个代码都在另一个事件侦听器中,对吧?如果是这种情况,您将多次绑定 onchange 处理程序,这可能会导致您描述的行为。将执行 $page.find(".checkboxes").change 的部分移到其他事件处理程序之外!

标签: javascript internet-explorer checkbox onchange


【解决方案1】:
    .focus(function(){})

或者你使用

    .click(function(){})

【讨论】:

  • 我认为“点击”是最好的,因为您可以选择一个复选框。
猜你喜欢
  • 2020-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-30
  • 2021-11-20
  • 2022-06-10
  • 2012-04-09
  • 1970-01-01
相关资源
最近更新 更多