如何在JS文件中添加jQuery [英] How to add jQuery in JS file
本文介绍了如何在JS文件中添加jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些特定于排序表的代码。由于代码在大多数页面中很常见,我想制作一个JS文件,其中包含代码,所有使用它的页面都可以从那里引用它。
I have some code specific to sorting tables. Since the code is common in most pages I want to make a JS file which will have the code and all the pages using it can reference it from there.
问题是:如何将jQuery和表格排序器插件添加到该.js文件中?
Problem is: How do I add jQuery, and table sorter plugin into that .js file?
I试过这样的事情:
document.writeln('<script src="/javascripts/jquery.js" type="text/javascript"></script>');
document.writeln('<script type="text/javascript" src="/javascripts/jquery.tablesorter.js"></script>');
但这似乎不起作用。
最好的方法是什么?
推荐答案
var script = document.createElement('script');
script.src = 'http://code.jquery.com/jquery-1.11.0.min.js';
script.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(script);
这篇关于如何在JS文件中添加jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文