2014-01-15 128 views
0

我正在使用选定的jquery插件,并希望在调用change事件时立即触发打开的事件,以便显示包含所有选项的搜索栏。选择 - 在更改事件后触发打开事件

HTML代码

$(document).ready(function() { 
    $('#myselect').chosen().change(function(){ 
    // alert('change event called'); 
    $('#myselect').trigger('chosen:activate'); 
    $('#myselect').trigger('chosen:open'); 
    add_food({{profile_id}}); 
    }); 
}); 

虽然$('#myselect').trigger('chosen:open');打开了搜索栏和选项,当我试图在控制台上

<select id="myselect" data-placeholder="Add foods you can buy here." style="height:30px;width: 100%" class="chosen-select" > 
    <option value=""></option> 
    {% for each in food_list %} 
     <optgroup label={{each.node}}> 
      {% if each.children %} 
       {% for eachchild in each.children %} 
        <option>{{eachchild}}</option> 
       {% endfor %} 
      {% else %} 
       <option>{{each.node}}</option> 
      {% endif %} 
     </optgroup> 
    {% endfor %} 
</select> 

jqyery代码,但它不更改事件函数内工作。我错在哪里?

回答

0

由于您没有包含足够有用的代码,因此很难准确理解您的要求。

有我创建了一个小提琴显示了这个工作:http://jsfiddle.net/4VLrB/2/

你包括chosen.css和chosen.jquery.js(后你有jQuery的)?

<script type='text/javascript' src='jquery...'></script> 
<script type='text/javascript' src='chosen.jquery.js'></script>