我有一个带有脚本标记的Grails视图,如下所示:
<script type="text/javascript"> /* the first setInterval */ setInterval( function() { console.log("Test..."); }, 5000 ); setInterval( function() { console.log("Test... (2)"); }, 5000 ); GetContent(1); GetContent(2); GetContent(3); GetContent(4); setInterval( Test0, 5000 ); setInterval( Test2, 5000 ); setInterval( ShowTime, 1000 * 10 ); setInterval( Test3, 1000 * 9 ); setInterval( Test1, 1000 * 8 ); </script>我想知道,为什么第一个setInterval从未执行过? 不知何故,第一个javascript函数调用从未执行过。 函数调用显示在html(视图源代码)中,但它从未执行过。
如果我复制第一个setInterval并将其粘贴在第一个下面,那么我有两个相同的函数调用,只有一个执行。
控制台每5000毫秒只写一次“Test ...”。
这是Grails中的错误吗?
I have a Grails view with script tag like this:
<script type="text/javascript"> /* the first setInterval */ setInterval( function() { console.log("Test..."); }, 5000 ); setInterval( function() { console.log("Test... (2)"); }, 5000 ); GetContent(1); GetContent(2); GetContent(3); GetContent(4); setInterval( Test0, 5000 ); setInterval( Test2, 5000 ); setInterval( ShowTime, 1000 * 10 ); setInterval( Test3, 1000 * 9 ); setInterval( Test1, 1000 * 8 ); </script>I wonder, why the first setInterval never executed? Somehow, the first javascript function call never executed. The function call shows up in the html (view source), but it never executed.
If I copy the first setInterval and paste it right underneath the first one, so I have 2 identical function call, only one of them get executed.
The console only write "Test..." once each 5000 milliseconds.
Is it a bug in Grails?
最满意答案
我的问题的答案只是将这些javascript函数调用绑定到文档的ready事件。
<script type="text/javascript"> $(document).ready( function() { /* the first setInterval */ setInterval( function() { console.log("Test..."); }, 5000 ); setInterval( function() { console.log("Test... (2)"); }, 5000 ); GetContent(1); GetContent(2); GetContent(3); GetContent(4); setInterval( Test0, 5000 ); setInterval( Test2, 5000 ); setInterval( ShowTime, 1000 * 10 ); setInterval( Test3, 1000 * 9 ); setInterval( Test1, 1000 * 8 ); }; </script>现在,一切按预期执行。
The answer to my question is simply to bind those javascript function calls to document's ready event.
<script type="text/javascript"> $(document).ready( function() { /* the first setInterval */ setInterval( function() { console.log("Test..."); }, 5000 ); setInterval( function() { console.log("Test... (2)"); }, 5000 ); GetContent(1); GetContent(2); GetContent(3); GetContent(4); setInterval( Test0, 5000 ); setInterval( Test2, 5000 ); setInterval( ShowTime, 1000 * 10 ); setInterval( Test3, 1000 * 9 ); setInterval( Test1, 1000 * 8 ); }; </script>Now, everything executed as expected.
第一个javascript函数调用从未执行过(first javascript function call never executed)我有一个带有脚本标记的Grails视图,如下所示:
<script type="text/javascript"> /* the first setInterval */ setInterval( function() { console.log("Test..."); }, 5000 ); setInterval( function() { console.log("Test... (2)"); }, 5000 ); GetContent(1); GetContent(2); GetContent(3); GetContent(4); setInterval( Test0, 5000 ); setInterval( Test2, 5000 ); setInterval( ShowTime, 1000 * 10 ); setInterval( Test3, 1000 * 9 ); setInterval( Test1, 1000 * 8 ); </script>我想知道,为什么第一个setInterval从未执行过? 不知何故,第一个javascript函数调用从未执行过。 函数调用显示在html(视图源代码)中,但它从未执行过。
如果我复制第一个setInterval并将其粘贴在第一个下面,那么我有两个相同的函数调用,只有一个执行。
控制台每5000毫秒只写一次“Test ...”。
这是Grails中的错误吗?
I have a Grails view with script tag like this:
<script type="text/javascript"> /* the first setInterval */ setInterval( function() { console.log("Test..."); }, 5000 ); setInterval( function() { console.log("Test... (2)"); }, 5000 ); GetContent(1); GetContent(2); GetContent(3); GetContent(4); setInterval( Test0, 5000 ); setInterval( Test2, 5000 ); setInterval( ShowTime, 1000 * 10 ); setInterval( Test3, 1000 * 9 ); setInterval( Test1, 1000 * 8 ); </script>I wonder, why the first setInterval never executed? Somehow, the first javascript function call never executed. The function call shows up in the html (view source), but it never executed.
If I copy the first setInterval and paste it right underneath the first one, so I have 2 identical function call, only one of them get executed.
The console only write "Test..." once each 5000 milliseconds.
Is it a bug in Grails?
最满意答案
我的问题的答案只是将这些javascript函数调用绑定到文档的ready事件。
<script type="text/javascript"> $(document).ready( function() { /* the first setInterval */ setInterval( function() { console.log("Test..."); }, 5000 ); setInterval( function() { console.log("Test... (2)"); }, 5000 ); GetContent(1); GetContent(2); GetContent(3); GetContent(4); setInterval( Test0, 5000 ); setInterval( Test2, 5000 ); setInterval( ShowTime, 1000 * 10 ); setInterval( Test3, 1000 * 9 ); setInterval( Test1, 1000 * 8 ); }; </script>现在,一切按预期执行。
The answer to my question is simply to bind those javascript function calls to document's ready event.
<script type="text/javascript"> $(document).ready( function() { /* the first setInterval */ setInterval( function() { console.log("Test..."); }, 5000 ); setInterval( function() { console.log("Test... (2)"); }, 5000 ); GetContent(1); GetContent(2); GetContent(3); GetContent(4); setInterval( Test0, 5000 ); setInterval( Test2, 5000 ); setInterval( ShowTime, 1000 * 10 ); setInterval( Test3, 1000 * 9 ); setInterval( Test1, 1000 * 8 ); }; </script>Now, everything executed as expected.
发布评论