国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > WEB開發(fā) > 正文

在頁面中動態(tài)載入外部javascript

2024-04-27 13:53:19
字體:
供稿:網(wǎng)友

有時候需要在網(wǎng)頁中某個div載入之后,動態(tài)引入一段javascript,IE下的解決方案:

以下為引用的內(nèi)容:
CODE:
newjs. onreadystatechange = function ( ) {
if (newjs. readyState == 'loaded' ) {
// ready!
}
}

newjs. onload = function ( ) {
// ready!
}

主要利用了onload以及onreadystatechange事件。把這個加以利用,也能動態(tài)載入外部css。下面是同時適合Ie/firefox的寫法。

以下為引用的內(nèi)容:
CODE:
var css;
function include_css (css_file ) {
var html_doc = document. getElementsByTagName ( 'head' ) [ 0 ];
css = document. createElement ( 'link' );
css. setAttribute ( 'rel', 'stylesheet' );
css. setAttribute ( 'type', 'text/css' );
css. setAttribute ( 'href', css_file );
html_doc. appendChild (css );

// alert state change
css. onreadystatechange = function ( ) {
if (css. readyState == 'complete' ) {
alert ( 'CSS onreadystatechange fired' );
}
}
css. onload = function ( ) {
alert ( 'CSS onload fired' );
}
return false;
}

var js;
function include_js (file ) {
var html_doc = document. getElementsByTagName ( 'head' ) [ 0 ];
js = document. createElement ( 'script' );
js. setAttribute ( 'type', 'text/javascript' );
js. setAttribute ( 'src', file );
html_doc. appendChild (js );

js. onreadystatechange = function ( ) {
if (js. readyState == 'complete' ) {
alert ( 'JS onreadystate fired' );
}
}

js. onload = function ( ) {
alert ( 'JS onload fired' );
}
return false;
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 博兴县| 罗定市| 嘉义县| 新巴尔虎右旗| 南丰县| 修武县| 阜新| 鹤峰县| 湄潭县| 无棣县| 当阳市| 大悟县| 五指山市| 拜城县| 丰顺县| 谷城县| 襄垣县| 舟曲县| 山东| 巴塘县| 汉源县| 尉氏县| 前郭尔| 巴塘县| 永昌县| 镇江市| 裕民县| 邹城市| 吴桥县| 崇仁县| 黎平县| 博客| 中方县| 安福县| 宝山区| 景东| 大冶市| 连山| 阿图什市| 永济市| 嵊州市|