• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

使用脚本替换CSS_css

css 搞代码 7年前 (2018-06-10) 201次浏览 已收录 0个评论
判断客户端浏览器载入样式表

if (browser.isNS4x == true) {
 document.write(‘<link rel=”stylesheet” type=”text/css” href=”ns4.css“>’);
}
else {
 document.write(‘<link rel=”stylesheet” type=”text/css” href=”advanced.css”>’);
}

判断客户端浏览器控制页面样式

if (browser.isNS4x == true) {
 
 // Tag selectors
 document.tags.body.fontSize = ’11px’;
 document.tags.td.fontSize = ’11px’;
 document.tags.th.fontSize = ’11px’;
 document.tags.p.fontSize = ’11px’;
 
 // Class selectors
 document.classes.someClass.all.fontSize = ’11px’;
 
 // Id selectors
 document.ids.someId.fontSize = ’11px’;
}

Using the DOM
The best way to work with CSS from JavaScript is to use the DOM. You can disable or remove existing stylesheets, add new stylesheets, make existing <link> tags point to different .css files, add or remove rules, add or remove declarations, change classes or styles on existing elements, whatever you like. But there is a catch: the browsers you want to manipulate styles for must support the DOM methods needed to do the manipulation you want. So instead of doing browser detection, it would be better to do object detection on the DOM objects you want to manipulate. The DOM is a huge topic and I’m not going to tackle it here. Instead, I direct readers to an article on Manipulating CSS using the W3C DOM and Peter-Paul Koch’s DOM Compatibility Chart for CSS.

Referrence
CSS filtering using javascript http://www.dithered.com/css_filters/js_summary.html

欢迎大家阅读《使用脚本替换CSS_css》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:使用脚本替换CSS_css
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址