开发者

js function not working properly, why?

The function isn't working when i'm using $(document).ready(function () { ..... }); but it works when i invoke. please take a look.

#test {height:25%,width:25% }

<body>
....
<div id="test">
  <image src="file.jpg" />
</div>
...
</div> </body>

js file (Not working) :

$(document).ready(function () { 
   $('#test').drag开发者_StackOverflow社区gable();
 });

js file (Working when a function is invoked)

function startDrag() {    // I just called this function from html files e.g. <div id="test" onmouseover="startDrag();">....</div>
 $('#test').draggable();
}


I wonder if this is something that relies on the document being 'loaded' as opposed to 'ready'

Does the following work?

$(window).load(function() {
    $('#test').draggable();
}

Also, try including your JS File at the foot of your page (i.e. below the #test html)


Both should work. I suggest to open the JavaScript debugger and set a breakpoint to see when and if the code is executed.

Also check the console for any errors. Maybe it's a silly typo somewhere,


Can you try this?

$(function () { 
    $('#test').draggable();
});

It might not make a difference, but this is the way I'm used to :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜