网络编程
位置:首页>> 网络编程>> JavaScript>> Script 元素 type 属性的妙用

Script 元素 type 属性的妙用

作者:blank 来源:蓝色理想 发布时间:2011-03-07 16:13:00 

标签:script,type,属性

我们经常使用动态创建 JavaScript 的方式来实现 JavaScript 文件的无阻塞(Non-blocking)、并行下载(Parallel )。

其实还可以添加自定义的 type 属性(比如 text/cache),达到预加载但不执行的效果:



var doc = document,
    el = doc.createElement("script"),
    head = doc.getElementsByTagName('head')[0];
    el.src = "http://yui.yahooapis.com/2.8.2r1/build/yahoo-dom-event/yahoo-dom-event.js";
    el.type = "text/cache";
    head.insertBefore(el, head.firstChild);


注:Firefox 3.6.x 不请求 JavaScript 文件。

扩展阅读:

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com