2012-05-30 47 views
1

我爲我的選擇器使用了一個插件。它被稱爲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"); }); 

任何人有任何想法我可以在這裏嘗試嗎?

回答

3

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

表單域更改

當表單字段工作,你經常要執行一些行爲值已選擇或取消選擇後。每當用戶選擇一個選定的字段時,它會在原始表單字段上觸發「更改」事件*。那就讓我們來做這樣的事情吧:

$("#form_field").chosen().change(…); 
相關問題