我使用的是 Rails4 版本。 以下是我需要做出的选择:
当我第一次选择并单击“添加”按钮时,加载指示器没有出现。当我第二次这样做并单击“添加”按钮时,加载指示器出现并且工作正常。我不太擅长 javascript,所以我真的不知道如何在第一次尝试时触发加载指示器。这是我的代码:
我的 View 文件:
<div id="loading-indicator" style="display:none">
<%=" Wait..."%><%= image_tag("/images/ajax-loader-8.gif", :id => "loading-indicator") %>
</div>
我的 CSS 文件:
#loading-indicator {
left: 10px;
top: 10px;
}
我的“create.js”文件:
$(document)
.ajaxStart(function() {
$('#loading-indicator').show();// show on any Ajax event.
$("#notice").html("<%= escape_javascript(render :partial => 'layouts/flash' ,
:locals => { :flash => flash }).html_safe %>").hide();
})
.ajaxStop(function() {
$("#notice").html("<%= escape_javascript(render :partial => 'layouts/flash' ,
:locals => { :flash => flash }).html_safe %>").show();
$('#loading-indicator').hide(); // hide it when it is done.
});
$("#transaction_paypal").html("<%= escape_javascript(render :partial => 'trans')%>");
谢谢。
最佳答案
我在 application.js 文件中添加了以下 js 行:
$(document)
.ajaxStart(function() {
$('#loading-indicator').show();// show on any Ajax event.
})
.ajaxStop(function() {
$('#loading-indicator').hide(); // hide it when it is done.
});
关于javascript - 选择单选按钮并单击 'add' 按钮时不显示加载指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25306090/