我正在为我的选择器使用一个插件。它叫做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"); });
有人知道我可以在这里尝试什么吗?
最佳答案
参见 http://harvesthq.github.com/chosen/
表单字段更改
使用表单域时,您通常希望在选择或取消选择值后执行某些操作。每当用户在 Chosen 中选择一个字段时,它都会在原始表单字段上触发“更改”事件*。让我们做这样的事情:
$("#form_field").chosen().change( … );
关于javascript - 将更改事件添加/委托(delegate)/绑定(bind)到 Chosen 插件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10816841/