开发者

jquery - switch javascript file in head

I'm learning jquery and I have a method that I want to implement. I want to test out switch between multiple JS files on one HTML page. So, I want to be able to click a link on the HTML page which will then load another JS script. I've done this so far:

$("#jswitch-1").click(function() {
$('head').append('<script src="js/my-jquery-1.js" type="text/javascript"></script>');});

jswitch-1 is the id of an HTML link. This method works but I can't see it added to the source code when I view source. Will I also need to remove the cu开发者_运维技巧rrent JS file with this function and then load the next one? Or is there another more efficient way of doing this?


Viewing source will always show the source, as fetched from the webserver.

If you want to view a serialization of the current state of the DOM, then you will need a DOM Inspector. Firebug has a good one (for Firefox), Opera has Dragonfly, and other browsers tend to have them built in.

That said, you should probably be using getScript anyway.

Will I also need to remove the current JS file with this function and then load the next one?

So long as you override every function, there shouldn't be any issues but watch out for race conditions and event handlers holding copies of previous versions of the functions.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜