2013-03-11 59 views
0

我在Rails3中調用AJAX和替換結果綁定jQuery的鎖定了選擇框與阿賈克斯

的coffee.js表一個簡單的形式是

id_handler = -> 
     $.ajax 
      url: "/surveys_search" 
      data: 
      id: $(this).val() 
      name: $(this).prop("name") 

    input_handler = -> 
     $.ajax 
      url: "/surveys_search" 
      data: 
      search: $(this).val() 
      name: $(this).prop("name") 

    $(document).ready -> 
     $(document).on "change", "select", id_handler 
     $(document).on "keyup", "input", input_handler 


     $("#survey_active").bind "change", -> 
     $.ajax 
      url: "/surveys_search" 
      data: 
      survey_active: (if $(this).is(":checked") then 1 else 0) 

我的形式是

<div class="well well-small"> 
    <h4>Quick search</h4> 
    <dl class="dl-horizontal"> 
     <dt><strong>Quiz:</strong></dt> <dd> 
     <%= text_field_tag :surveys_search, params[:surveys_search], :class=>"text-field" %> 
     <%= select_tag 'survey_select', options_from_collection_for_select(Survey.all, 'id', 'name'),:prompt=>"All"%> 
     <strong>Published?</strong> <%= check_box_tag 'survey_active' %> 

     </dd> 
     <dt><strong>Prize:</strong></dt> <dd><%= text_field_tag :prizes_search, params[:prizes_search], :class=>"text-field" %> <%= select_tag 'prize_select', options_from_collection_for_select(Prize.all, 'id', 'name'),:prompt=>"All"%></dd> 
     <dt><strong>Location:</strong></dt> <dd><%= text_field_tag :locations_search, params[:prizes_search], :class=>"text-field" %> <%= select_tag 'location_select', options_from_collection_for_select(Location.all, 'id', 'name'),:prompt=>"All"%></dd> 
    </dl> 
    </div> 

我的問題是,當我改變下拉的值,選擇框變得不可改變,直到我然後重新點擊另一個元素,然後嘗試重新更改它。

切實履行其鎖定選擇下拉當我改變它

在形式上面我改變TOP /第一選擇下拉,再經過AJAX調用頂部選擇向下被鎖定,同時底部/第三選擇框也是焦點,我同時獲得了兩個焦點對象

有人可以解釋如何避免它嗎?

回答

0
id_handler = -> 
    $.ajax 
     url: "/surveys_search" 
     data: 
     id: $(this).val() 
     name: $(this).prop("name") 
     success: $(this).blur() 
+0

我知道這個作品,但想知道爲什麼它不工作沒有它...... – user1320651 2013-03-11 14:07:37