如何按需加载jqtouch
我正在尝试像这样按需加载 jqtouch:
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(function() {
$.getScript("js/jqtouch.min.js", function() {
$.jQTouch();
});
});
</script>
Firebug 输出: $(_3c.selector).tap 不是函数
如果我在脚本中包含 jqtouch.min.js ,就像我对 jquery.js 所做的那样并调用 $ .jQtouch,一切都会正常工作。但是,我只想在需要时加载 jqtouch,但我似乎无法让它工作。我还尝试向 jqtouch.min.js 发送 ajax post 并收到相同的错误。
I'm trying to load jqtouch on-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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您按需加载 jqtouch 脚本时, $(document).ready 事件会在加载脚本之前触发,因此永远不会执行 jqtouch 初始化脚本。
解决方案很糟糕....您必须将 jqtouch 脚本初始化绑定从 修改
为
...并且您必须修改自己的代码以在加载脚本后触发就绪事件
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
to
...and you have to modify your own code to fire the ready event after loading the script