为什么我的javaScript无法在本地或服务器上运行,而在jsFiddle上运行
这是工作jsfiddle的链接 http://jsfiddle.net/akshaytyagi/SD66b/
This is a link to the working jsfiddle http://jsfiddle.net/akshaytyagi/SD66b/
以下是我尝试在我的网站上运行的代码(与一个jsFiddle相同)
and following is the code that I am trying to run on my website ( same as the one jsFiddle )
我在两台计算机上尝试过.我在做什么错了?
I have tried on two computers. What am I doing wrong?
<html>
<head>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var tips = [
"creative",
"innovative",
"awesome",
"amazing",
"social"
];
setInterval(function() {
var i = Math.round((Math.random()) * tips.length);
if (i == tips.length)--i;
$('#tip').slideUp(500, function() {
var $this = $(this);
$this.html(tips[i]);
$this.toggleClass('first second');
$this.slideDown(500);
});
}, 3 *1000);
});
</script>
</head>
<body>
<div style=" background-position:center; background-repeat:no-repeat; background-color:#c84d5f; height:500px">
<div class="thousand">
<div style="font-size:72px; font-family:Museo; padding-top:100px; padding-left:auto; padding-right:auto; color:#FFF;">The <span id="tip">creative</span><br />brand.
</div>
</div>
</div>
</body>
</html>
我复制并粘贴了HTML,并且在}, 3 * 1000);
之后有一个特殊的字符.
I copy and pasted your HTML, and after }, 3 * 1000);
there is a special char.
删除整行(}, 3 * 1000);
),然后重新输入.
Delete that whole line (}, 3 * 1000);
) and re-type it.
请参阅:
正如andyb所评论的那样,如果您是在本地加载文件,则jQuery网址将无法工作.您可以将其更改为http://或将文件上传到某处.
As andyb has commented, if you're loading the file locally your jquery url wont work. You can either change it to http:// or upload your file somewhere.