.submit() 后 RangeSliders 消失

RangeSliders disappears after .submit()

我有一个下拉菜单和一个范围滑块,使用 jQuery 移动设备作为 Rails 表单:

<%= form_tag(profile_path, remote: true, id: 'search_forms') do %>
  <%= select_tag 'q[activity]', options_from_collection_for_select(activities, :slug, :title, q[:activity]), id: 'activ_sel', prompt: "Select an activity" %>

  <div id="time-slider" data-role="rangeslider">            
    <input name="range1a" id="range1a" min="4" max="21" value="<%= @h1 %>" type="range" />
    <input name="range1b" id="range1b" min="4" max="21" value="<%= @h2 %>" type="range" />
  </div>

  <script>
    $("#activ_sel").change(function(){
      $('#search_forms').submit();
     });
  </script>

<% end %>

我目前的设置是在下拉列表更改后提交,之后我也想为滑块实现这个。

虽然提交工作正常,但问题是提交后滑块中断,如下所示:

我的 javascripts 资产上有 jQuery 移动库,并通过 application.js 文件中的 //= require_tree . 行加载它。

我对为什么这不起作用的解释是,在调用 .submit() 并将表单设置为 remote: true 时,请求已发送但没有触发 jQuery 的库重新加载AJAX 电话的预期移动。

Note: Remember to attach the mobileinit handler after you have loaded jQuery, but before you load jQuery Mobile, because the event is triggered as part of jQuery Mobile's loading process.

我在想提交无限(不确定为什么)用于范围滑块的 div 并且没有再次绑定,因为它没有重新加载库。

无论如何,解决此问题的方法是在父元素上调用 .trigger("create") 以重新附加小部件。

关于.trigger()

Description: Execute all handlers and behaviors attached to the matched elements for the given event type.

感谢@Omar 的帮助,也请考虑将此问题作为重复问题关闭:jquery mobile trigger create method

参考:http://api.jquerymobile.com/rangeslider/