我需要一些有關自定義jquery事件的任何ideea的指導/建議。 從html選擇我試圖創建一個「組合框」,用戶可以在其中鍵入文本,選項列表將被該輸入文本過濾。 一個選擇的方式,HTML代碼一樣從html選擇新創建的combox的jQuery事件選擇
<select name="foo_select" id="foo_id">
<option value="foo_option_value_1">foo_option_text_1</option>
<option value="foo_option_value_2">foo_option_text_2</option>
<option value="foo_option_value_3">foo_option_text_3</option>
</select>
將與
<div class="combo_container" id="foo_select_container" style="position:relative">
<input type="text" class="combo_text" />
<input type="hidden" name="foo_select" id="foo_id" />
<div class="combo_arrow">
<ul style="position:absolute;">
<li id="foo_option_value_1">foo_option_text_1</li>
<li id="foo_option_value_2">foo_option_text_2</li>
<li id="foo_option_value_3">foo_option_text_3</li>
</ul>
</div>
所以被替換,當用戶選擇的與類輸入一定的「選項」從新創造的「組合框」「 combo_text「選項的文本被插入,並在隱藏的輸入選項的ID中插入。
現在,我需要做的就是知道用戶何時選擇一個選項。基本上我需要做的是創建相當於jQuery('#foo_id').change(function(){do_someting});爲我新創建的組合框,但我沒有ideea從哪裏開始。
如果有人有任何ideea我會apreciate。
更新。
我提到我儘量保持html選擇的行爲。該組合框的功能,如:對向上/向下箭頭上集中combo.text用戶可以選擇一個值,並在輸入值被改變,調用函數選擇()或逃避什麼chages - 即使用戶使用上/下箭頭選擇了其他值。
所以我想我需要做的是這樣..當隱藏輸入$(「#foo_id」)改變做些事情,所以我需要找出當此輸入的值發生變化。
謝謝..
感謝您的快速響應。點擊它可以,但我已儘量保留html選擇的行爲,所以選擇一個選項是通過點擊列表項**和**來輸入時輸入** .combo_text **的重點。當這兩個事件中的一個觸發了一個函數** Select()**被調用時,它將輸入值,輸入文本和添加的一個類「選中」到選定的列表項中。 – stef 2012-03-08 14:11:44