0
我正在使用jQuery slideToggle在我的Rails应用程序中切换元素。当元素可见时,我想在输入字段上自动对焦。 :autofocus => true
的作品,但只有第一次输入字段是可见的。如果我切换回该元素以隐藏它,然后再次切换以显示它,:autofocus
已消失。我必须刷新页面才能使:autofocus
正常工作。谁能帮我解决这个问题吗?使用slideToggle强制自动对焦,无需重新加载应用程序
这里是我的代码:
<%= link_to 'expand', nil, :class => 'button white', :id => "newForm", :remote => true %></li>
的jQuery:
$(function(){
$('a#newForm').click(function() {
$('ul.form').slideToggle('500', function() {
// Animation complete.
});
});
});
形式:
<ul class="form">
<%= form_for(Object.new) do |f| %>
<div id="titleHolder">
<%= f.text_field :title, :id =>"objectProfile", :autofocus => true %>
</div>
<div id="placeholder">
<%= f.text_area :body, :id =>"objectProfile" %>
</div>
<li id="button">
<%= submit_tag 'SUBMIT', :class => 'button orange' %>
</li>
<% end %>
</ul>
工作很好,谢谢! – tvalent2 2011-10-22 14:57:09