×

jquery动态加载js三种方法实例

作者:Terry2017.02.04来源:Web前端之家浏览:9437评论:0
关键词:JQueryJS
复制代码 代码如下:

<!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三种方法</title>
//方法一
<script language="网页特效">
$.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);
}
//够简单把!如果在浓缩以下你甚至可以用一行代码全部搞定:
//方法三
$("<scri"+"pt>"+"</scr"+"ipt>").attr({src:file,type:'text/javascript',id:'load'}).appendto($('head').remove('#loadscript'));
</script>

您的支持是我们创作的动力!
温馨提示:本文作者系Terry ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://www.jiangweishan.com/article/svg1486137600645.html

网友评论文明上网理性发言已有0人参与

发表评论: