admin 管理员组文章数量: 1086019
The following works perfectly fine...displays an alert every 10 seconds
<script type='text/javascript'>
function letsTest(){
alert("it works");
}
var uptimeId = window.setInterval(letsTest, 10000);
</script>
But when I place my letsTest
function in a file called javaScript.js, it no longer works.
main page:
<script src='lib/javaScript.js' type='text/javascript'>
var uptimeId = window.setInterval(letsTest, 10000);
</script>
javaScript.js
function letsTest(){
alert("it works");
}
I verified a thousand times over the path and spelling. I use my javaScript.js
in other places as well. Is it possible to set an interval with a function from another file?
The following works perfectly fine...displays an alert every 10 seconds
<script type='text/javascript'>
function letsTest(){
alert("it works");
}
var uptimeId = window.setInterval(letsTest, 10000);
</script>
But when I place my letsTest
function in a file called javaScript.js, it no longer works.
main page:
<script src='lib/javaScript.js' type='text/javascript'>
var uptimeId = window.setInterval(letsTest, 10000);
</script>
javaScript.js
function letsTest(){
alert("it works");
}
I verified a thousand times over the path and spelling. I use my javaScript.js
in other places as well. Is it possible to set an interval with a function from another file?
2 Answers
Reset to default 13<script src='lib/javsScript.js' type='text/javascript'>
var uptimeId = window.setInterval(letsTest, 10000);
</script>
You cannot provide both a src
and a body for a <script>
tag. One or the other.
You'll have to use two <script>
tags:
<script src='lib/javaScript.js'></script>
<script>
var uptimeId = setInterval(letsTest, 10000);
</script>
Actually the reason behind it may be ,that the variable uptimeId is not accessible inside the file javascript.js. Please let me know if I am wrong.
本文标签: Why can39t I use javascript setInterval with a function in an external fileStack Overflow
版权声明:本文标题:Why can't I use javascript setInterval with a function in an external file? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1743996813a2515726.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论