Code working in jsFiddle but not in browser

2019-01-01 07:33发布

I'm trying to run the following code, written on my local machine:

http://www.jsfiddle.net/WShdx/3/

Functionality-wise (ignore the broken images in the previous and next buttons, and the wrongly-sized main images) the click/hover function is working properly in jsfiddle. However, on my local machine it's not working at all.

For all intents and purposes the code is identical, except the local copy has this head section to load in the javascript/css files that are contained within the jsfiddle page:

<head>
  <title>Jquery Wizard</title>
  <link href="style.css" rel="stylesheet" type="text/css" />
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
  <script src="wizard.js" type="text/javascript" ></script>
</head>

Is there some wonderful function of jsFiddle that is making my code magically work, or am I missing something here?

2条回答
后来的你喜欢了谁
2楼-- · 2019-01-01 07:55

You chose to run the script-code "onload" on jsFiddle, that's the difference.

Without onload it will not find $('area') , because your script is placed inside the <head>, where the elements inside the <body> are still unknown.

查看更多
还给你的自由
3楼-- · 2019-01-01 08:16

I'd also advice anyone who run into such errors to use firebug or any debugging tool debug the script whenever such problems occur. Might be very simple yet frustrating problems like an Uncaught SyntaxError: Unexpected token ILLEGAL error. Debuggers come in very handy!

查看更多
登录 后发表回答