JQuery无法绑定可选择的click事件 [英] JQuery Cannot bind click event on selectable

查看:135
本文介绍了JQuery无法绑定可选择的click事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该非常简单,但我无法检索点击事件并在 可选择的 JQuery UI项目。

This should be very simple, but I am unavailable to retrieve click event and fire a function on a selectable item for JQuery UI.

<div id="a">
<ol id="selectable-a">
  <li class="a-item">1</li>
  <li class="a-item">2</li>
  <li class="a-item">3</li>
  <li class="a-item">4</li>
</ol>
</div>

Javascript:

Javascript:

$("#selectable-a").selectable();

$("li .a-item").click(function () {
  console.log("Executing command");
});

但点击事件永远不会被解雇。

But the click event is never fired.

我已经考虑了谷歌。


  • 尝试替换 .click( by .bind('click',但它不会改变任何内容

  • 在jquery论坛中,他们提出了这个问题并且有人给出了调整内部功能的解决方案,而不是为我工作(content.data('selectable')总是未定义,无论如何)

  • 将距离设置为1,这意味着用户需要将鼠标移动1个像素才能触发事件,这是一个坏主意。

  • 这个问题没有任何令人满意的答案。也就是说,我不仅希望在所选项目上获得点击事件,而且还在任何项目上。

  • try to replace .click( by .bind('click', but it does not change anything
  • In the jquery forum they raise this problem and someone gives a solution tweaking the inner functionning, which does not work for me (content.data('selectable') is always undefined, no matter what)
  • Setting the distance to 1, meaning that the user needs to move a mouse by 1 pixel so that the event is fired, is a bad idea.
  • This SO question does not have any satisfactory answer. Namely, I don't just want to get the click event on a selected item, but on any item.

关于如何解决问题的任何想法问题?

Any idea on how to solve the problem?

推荐答案

使用 $(li.a-item)而不是 $(li .a-item)

第一个寻找李a-item类;第二个在list元素中查找带有a-item类的元素。

The first one looks for a li with the a-item class ; the second looks for an element with the a-item class inside a list element.

这篇关于JQuery无法绑定可选择的click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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