jquery动态加载与去除js代码的三种方法
利用jquery动态加载文件很方便,使用$.getscript("test.js");就可以了。
例1,动态加载js的jquery实例代码。
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>jquery 动态加载js三种方法 - www.jbxue.com</title>
<script language="javascript">
$.getscript("test.js");
//方法二
function loadjs(file){
var head = $('head').remove('#loadscript');
$("<scri"+"pt>"+"</scr"+"ipt>").attr({src:file,type:'text/javascript',id:'load'}).appendto(head);
}
//一行代码搞定js代码加载:
//方法三
$("<scri"+"pt>"+"</scr"+"ipt>").attr({src:file,type:'text/javascript',id:'load'}).appendto($('head').remove('#loadscript'));
</script>
</head>
<body>
</body>
</html>
例2,jquery去除js
$("script[src='../static/js/wan_flow.js']").remove();
您可能感兴趣的文章:
jquery动态加载与去除js代码的三种方法
jquery动态加载js三种方法实例
jquery 动态加载js的多种方法汇总
js 禁止文本框输入空格的代码
jquery getScript动态加载JS方法改进详解
jquery 常用操作整理 基础入门篇
js onclick事件传参数的方法分析
如何使用jquery动态加载js,css文件实现代码
怎么判断js脚本加载是否完成
jquery动态添加option示例