JQuery在事件上加载脚本(单击)

$('#selector').click(function() { // here I would like to load a javascript file // let's say /js/script-on-click-event.js }); 

这有点可能吗? 我不确定,但我记得在JQuery文档中读到了一个函数,但我在这里找不到它,也许它已被弃用或者我在其他地方看到了它?

基本上我想要的是在点击事件上加载脚本。

像jQuery.getScript这样的东西

 $("#selector").click(function(){ $.getScript("http://dev.jquery.com/view/trunk/plugins/color/jquery.color.js"); }); 

你可以只使用javascript做同样的事情:

 var script = document.createElement('script'); script.src = 'http://somesite.com/somescript.js'; script.type = 'text/javascript'; document.body.parentNode.appendChild(script); 

使这项工作的库是LAB JS