</script>" />
开发者

How to load jqtouch on-demand

I'm trying to load jqtouch o开发者_如何学Cn-demand like so:

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
    $(function() {
        $.getScript("js/jqtouch.min.js", function() {
             $.jQTouch();
        });
    });     
</script>

Firebug outputs: $(_3c.selector).tap is not a function

If I include jqtouch.min.js in a script, like I did for jquery.js and call $.jQtouch, everything will work correctly. However, I'd like to load jqtouch only when I need to, however I can't seem to get it to work. I also tried doing an ajax post to jqtouch.min.js and received the same error.


When you load the jqtouch script on-demand, the $(document).ready event fires before the script is loaded, so the jqtouch initialization script is never executed.

The solution sucks....you have to modify the jqtouch script initialization binding from

$(document).ready(function(){...})

to

$(document).bind('ready',function(){...})

...and you have to modify your own code to fire the ready event after loading the script

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
    $(function() {
        $.getScript("js/jqtouch.min.js", function() {
             $(document).trigger('ready');
             $.jQTouch();
        });
    });     
</script>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜