« 上一篇 | 下一篇»

CSS on demand-load css file dynamically

Now,I'm developing a XXX product based on AJAX.So i will update a region of one page dynamiclly.Because of i made the layout under Web Standard principle(DIV+CSS),there will be many CSS files for layout and style.If i update region A,the new HTML needs new css files.So i don't wanna link all css files at that main page.The codes below will give you a common way to load specify css file dynamiclly though it's simple.(Test under Firefox1.5 IE6 SP1)
var head = document.getElementsByTagName('HEAD').item(0);
var style = document.createElement('link');

style.href
= './css/add_user.css';

style.rel
= 'stylesheet'

style.type
= 'text/css';

head.appendChild(style);

The whole script codes here including AJAX.update class of Prototype
// JavaScript Document function navBtnOnClick(layerName){ var layerNames = new Array("folder","manage"); for(var i = 0;i

(0) 评论    (95) 引用   

Total 0 Comments on "CSS on demand-load css file dynamically"

发表评论

称呼 (required)

标题

个人主页(可选)

邮箱地址(可选)

Auth Image