首先祝各位大哥,国庆中秋快乐求一段代码如果是ie6用户
则调用
<link rel="stylesheet" type="text/css" href="http://www.xxxxx.com/ie6.css">其他浏览器用户如ie7、ie8、firefox、chrome、Safari调用 <link rel="stylesheet" type="text/css" href="http://www.xxxxx.com/ie7.css">可能的话最好能给个源码我是技术小白只会看简单的html代码再次感谢
则调用
<link rel="stylesheet" type="text/css" href="http://www.xxxxx.com/ie6.css">其他浏览器用户如ie7、ie8、firefox、chrome、Safari调用 <link rel="stylesheet" type="text/css" href="http://www.xxxxx.com/ie7.css">可能的话最好能给个源码我是技术小白只会看简单的html代码再次感谢
方法1:把所有的js写在一起,然后对应不同浏览器的用|隔开 style=IE6style|IE7style 方法2:width: 100px!important; /* IE7+FF */
width: 80px; /* IE6 */ 用important 的话ie6是不解析的
<link rel="stylesheet" type="text/css" href="http://www.xxxxx.com/ie6.css" disabled id="ie6c">
<link rel="stylesheet" type="text/css" href="http://www.xxxxx.com/ie7.css" disabled id="otherc">
<script type="text/javascript">
<!--
window.onload = function(){
navigator.userAgent.indexOf('MSIE 6.0') != -1
? document.getElementById('ie6c').disabled = false
: document.getElementById('otherc').disabled = false
}
//-->
</script>
<div></div>
// JavaScript Document
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
if ((version >= 5.5) && (document.body.filters))
{
for(var j=0; j<document.images.length; j++)
{
var img = document.images[j]
var imgName = img.src.toUpperCase()
if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
{
var imgID = (img.id) ? "id='" + img.id + "' " : ""
var imgClass = (img.className) ? "class='" + img.className + "' " : ""
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
var imgStyle = "display:inline-block;" + img.style.cssText
if (img.align == "left") imgStyle = "float:left;" + imgStyle
if (img.align == "right") imgStyle = "float:right;" + imgStyle
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
var strNewHTML = "<span " + imgID + imgClass + imgTitle
+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
img.outerHTML = strNewHTML
j = j-1
}
}
}
}
window.attachEvent("onload", correctPNG);
建立两个.css文件测试下就可以了.
经过测试的,保存为html就可看到效果,可以用IETest看多浏览器效果:<!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=utf-8" />
<title>无标题文档</title>
<script type="text/javascript"> var Sys = {}; var ua = navigator.userAgent.toLowerCase(); if (window.ActiveXObject) Sys.ie = ua.match(/msie ([\d.]+)/)[1] else if (document.getBoxObjectFor) Sys.firefox = ua.match(/firefox\/([\d.]+)/)[1] else if (window.MessageEvent && !document.getBoxObjectFor) Sys.chrome = ua.match(/chrome\/([\d.]+)/)[1] else if (window.opera) Sys.opera = ua.match(/opera.([\d.]+)/)[1] else if (window.openDatabase) Sys.safari = ua.match(/version\/([\d.]+)/)[1]; //以下进行测试
if(Sys.ie.toLowerCase()=="6.0")
{
document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/ie6.css\"> ");
}
else
{
document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/ie7.css\"> ");
}
//if(Sys.ie) document.write('IE: '+Sys.ie); //if(Sys.firefox) document.write('Firefox: '+Sys.firefox); //if(Sys.chrome) document.write('Chrome: '+Sys.chrome); //if(Sys.opera) document.write('Opera: '+Sys.opera); //if(Sys.safari) document.write('Safari: '+Sys.safari); </script>
</head><body><script>
if(Sys.ie) document.write('IE: '+Sys.ie); if(Sys.firefox) document.write('Firefox: '+Sys.firefox); if(Sys.chrome) document.write('Chrome: '+Sys.chrome); if(Sys.opera) document.write('Opera: '+Sys.opera); if(Sys.safari) document.write('Safari: '+Sys.safari);
</script></body>
</html>
var tmpBrowser=navigator.appName
var tmpBVersion=navigator.appVersion
var tmpVersion=tmpBVersion.split(";");
var tmpTrimVersion=tmpVersion[1].replace(/[ ]/g,"");
if(tmpBrowser=="Microsoft Internet Explorer" && tmpTrimVersion=="MSIE7.0"){
include_css('css7.css');
}
else if(tmpBrowser=="Microsoft Internet Explorer" && tmpTrimVersion=="MSIE6.0"){
include_css('css.css');
}
else{
include_css('css7.css');
}
function include_css(css_file) {
var css;
var html_doc = document.getElementsByTagName('head')[0];
css = document.createElement('link');
css.setAttribute('rel', 'stylesheet');
css.setAttribute('type', 'text/css');
css.setAttribute('href', '/images/'+css_file);
html_doc.appendChild(css);
}
</script>