为什么我的javaScript无法在本地或服务器上运行,而在jsFiddle上运行 [英] Why is my javaScript not working locally or on server, but working on jsFiddle

查看:79
本文介绍了为什么我的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.

这篇关于为什么我的javaScript无法在本地或服务器上运行,而在jsFiddle上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆