如何动态载入css文件? 比如针对用户浏览器的不同载入相应的css文件 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!--[if IE 6]><link rel="stylesheet" type="text/css" href="css/header4.css" /><![endif]--> <!--[if IE 7]><link rel="stylesheet" type="text/css" href="css/header3.css" /><![endif]--> <!--[if IE 8]><link rel="stylesheet" type="text/css" href="css/header2.css" /><![endif]--> <!--[if !IE]><link rel="stylesheet" type="text/css" href="css/header1.css" /><![endif]--> 先判断 . jsvar style = document.createElement('link');style.href = 'css.css';style.rel = 'stylesheet';style.type = 'text/css';document.getElementsByTagName('HEAD')[0].appendChild(style); 先判断浏览器 然后style.href 加载不同的css <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><script language="javascript">function check(){if(window.navigator.userAgent.indexOf("MSIE 8.0")>=1){//如果浏览器为IE 8.0alert("ie8");}else if(window.navigator.userAgent.indexOf("MSIE 7.0")>=1){//如果浏览器为IE 7.0setActiveStyleSheet("IE7.0_index_layout.css");//设置css样式表}else if(window.navigator.userAgent.indexOf("TencentTraveler")>=1){//如果浏览器为腾讯TTsetActiveStyleSheet("TT_index_layout.css");}else if(window.navigator.userAgent.indexOf("Maxthon")>=1){//如果浏览器为傲游setActiveStyleSheet("Maxthon_index_layout.css");}else if(window.navigator.userAgent.indexOf("MSIE 6.0")>=1){//如果浏览器为IE 6.0 alert("ie6");}else if(window.navigator.userAgent.indexOf("Firefox")>=1){//如果浏览器为Firefoxalert("Firefox");setActiveStyleSheet("FF_index_layout.css");}else if(window.navigator.userAgent.indexOf("Safari")>=1){//如果浏览器为SafarisetActiveStyleSheet("Safari_index_layout.css");}else if(window.navigator.appName=="Opera"){//如果浏览器为OperasetActiveStyleSheet("Opera_index_layout.css");}else{//如果浏览器为其它setActiveStyleSheet("default_index_layout.css");}}</script><body onload="check()"> <div class="main">Hello Word!Hello Word!Hello Word!</div></body></html> 想得到具有输入焦点的text input,js代码怎么实现? 滑动门代码中如何动态改变一个隐藏域的值 怎么才能验证输入的字符串只能是26个大小写字母和中文吗?配备字符串怎么写 关于数组的定义、赋值、取值 javascript 怎么取得form内flash的名字 鼠标放到下拉框显示注释的问题 问个简单的问题:窗口之间如何传值?? 求用javaSrcipe编写求二个数最大公约数的页面 如何比较两个时间的大小? 初来乍到,大家多多关照哦 js缺少对象的问题。代码简短,速进。 javascript小偷程序怎么写?
<link rel="stylesheet" type="text/css" href="css/header4.css" />
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="css/header3.css" />
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="css/header2.css" />
<![endif]-->
<!--[if !IE]>
<link rel="stylesheet" type="text/css" href="css/header1.css" />
<![endif]-->
style.href = 'css.css';
style.rel = 'stylesheet';
style.type = 'text/css';
document.getElementsByTagName('HEAD')[0].appendChild(style);
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<script language="javascript">
function check(){
if(window.navigator.userAgent.indexOf("MSIE 8.0")>=1){
//如果浏览器为IE 8.0
alert("ie8");
}
else if(window.navigator.userAgent.indexOf("MSIE 7.0")>=1){
//如果浏览器为IE 7.0
setActiveStyleSheet("IE7.0_index_layout.css");//设置css样式表
}
else if(window.navigator.userAgent.indexOf("TencentTraveler")>=1){
//如果浏览器为腾讯TT
setActiveStyleSheet("TT_index_layout.css");
}
else if(window.navigator.userAgent.indexOf("Maxthon")>=1){
//如果浏览器为傲游
setActiveStyleSheet("Maxthon_index_layout.css");
}
else if(window.navigator.userAgent.indexOf("MSIE 6.0")>=1){
//如果浏览器为IE 6.0
alert("ie6");
}
else if(window.navigator.userAgent.indexOf("Firefox")>=1){
//如果浏览器为Firefox
alert("Firefox");
setActiveStyleSheet("FF_index_layout.css");
}
else if(window.navigator.userAgent.indexOf("Safari")>=1){
//如果浏览器为Safari
setActiveStyleSheet("Safari_index_layout.css");
}
else if(window.navigator.appName=="Opera"){
//如果浏览器为Opera
setActiveStyleSheet("Opera_index_layout.css");
}
else{
//如果浏览器为其它
setActiveStyleSheet("default_index_layout.css");
}
}</script>
<body onload="check()">
<div class="main">Hello Word!Hello Word!Hello Word!</div>
</body></html>