我正在玩Bootstrap的
stateful buttons – 特别是加载状态,但仍然找不到正确的设置来使其工作。我有一个基于AJAX的简单形式,类似于:
<%=form_tag '/comments',:remote => true do %> <div><%=text_area_tag 'comment[text_comment]'%></div> <div><button class="btn btn-primary" data-loading-text="loading stuff..." >Post</button></div> <%end%>
但是当我点击POST按钮时,表单正在发送,但按钮效果(加载东西…)不显示,就像Bootstrap页面上的示例一样。
有人可以给我一个如何解决它的提示?
解决方法
您需要明确设置按钮处于加载状态。这样的事情
// Set up the buttons
$(button).button();
$(button).click(function() {
$(this).button('loading');
// Then whatever you actually want to do i.e. submit form
// After that has finished,reset the button state using
// $(this).button('reset');
}
我创造了一个工作的JSFiddle example。