【问题标题】:Adding/delegating/binding a change event to Chosen plugin?添加/委托/绑定更改事件到选择的插件?
【发布时间】:2012-05-30 13:01:24
【问题描述】:

我正在为我的选择器使用插件。它被称为Chosen。我正在尝试为以下任何内容添加一个侦听器,但我觉得该插件正在阻止任何事情发生。理想情况下,我想添加一个事件,以便每次有人将“标签”添加到多选组时,都会调用一个方法。然而,事实证明这比它应该的要困难得多。到目前为止,我已经尝试了以下方法:

//detect when input field changes
$(".chzn-choices").find("input").change(function () { alert("lol I worked"); });

//detect when option is clicked (I dont think this works as a click event is already     binded to these and something is preventing the default
$(".chzn-drop").delegate("li", "click", function () { alert("clicked"); });

有人知道我可以在这里尝试什么吗?

【问题讨论】:

    标签: javascript jquery binding jquery-chosen


    【解决方案1】:

    http://harvesthq.github.com/chosen/

    表单字段更改

    使用表单域时,您通常希望在选择或取消选择某个值后执行一些操作。每当用户在 Chosen 中选择一个字段时,它都会在原始表单字段上触发一个“更改”事件*。那让你做这样的事情:

    $("#form_field").chosen().change( … );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-10
      • 2023-03-31
      • 2023-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多