我的application.html.erb有一个简单的脚本来设置3秒的时间,同时显示一个gif。但代码不起作用。如果gif工作正常,如果文档。
有人可以告诉我这里做错了什么。
##application.html.erb
<script>function hideLoading() {
$("#loading").hide();
}
function showLoading() {
$("#loading").show();
}
function dosomething() {
showLoading();
setTimeout("hideLoading()", 3000);
return false;
}
</script>
</head>
<body>
<div id="loading">
<img src="/assets/loading2.gif" alt="loading" />
</div>
<%= yield %>
</body>
</html>
答案 0 :(得分:0)
好像你正在定义但从不调用dosomething()
,因此它永远不会被执行(除非你没有在调用它的地方发布代码)。在任何情况下,您都可以将alert('foo');
随机dosomething()
放入dosomething()
函数中,以检查它是否正在运行。
如果您正在使用jquery,这将是加载DOM后立即调用$(document).ready(function() {
dosomething();
});
的合适方式:
{{1}}