




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、用JS控制CSS基本样式的方法CSS code .class1width:10px; background-color: red;HTML code New Document window.onload=fnInit;function fnInit()/ 访问 styleSheet 中的一条规则 , 将其 backgroundColor 改为蓝色。var oStyleSheet=document.styleSheets0;var oRule=oStyleSheet.rules0;oRule.style.backgroundColor=#0000FF; aaa (2) New Document
2、window.onload = function()alert(document.getElementById(apDiv1).currentStyle.width) aaa 可以知道当前页面中引用还可以用 document.styleSheets(i).href的每个 css 的文件!另:CSS属性与JavaScript 编码对照表上次本人 _何向阳,在使用 js 修改 css 的中 margin-left 属性 未定义,后来,找了好多资料,才发现在 js 中, margin-left(一定要注意,时,总报 left的写法为 :marginLeft ,恍然大悟,希望遇到相同问题的朋友,谨慎对
3、待。)CSS与 JS紧密配合,为我们的页面增添了很多别致的效果。为了达到某种特殊 的效果我们需要用Javascript动态的去更改某一个标签的CSS属性。比如:鼠标经过一个图片时我们让图片加一个边框,代码可能是这样:JavaScript 中 style 后面的属性应该是什么?function imageOver(e) e.style.border=1px solid red;function imageOut(e) e.style.borderWidth=0; JavaScript CSS Style 属性对照表 盒子标签和属性对照css语法(不区分大小写)JavaScript语法(区分大小写
4、)borderBottom borderBottomColor borderBottomStyle borderBottomWidth borderColorborderLeft borderLeftColor borderLeftStyle borderLeftWidth borderRight borderRightColor borderRightStyle borderRightWidth borderStyle borderTop borderTopColor borderTopStyle borderTopWidth borderWidthclearfloatStyle margi
5、n margin-bottom margin-left margin-right margin-top padding padding-bottomborder border border-bottom border-bottom-color border-bottom-style border-bottom-width border-color border-left border-left-color border-left-style border-left-width border-right border-right-color border-right-style border-r
6、ight-width border-style border-top border-top-color border-top-style border-top-width border-width clear float margin marginBottom marginLeft marginRight marginTop padding paddingBottompadding-left padding-right padding-toppaddingLeftpaddingRight paddingTop颜色和背景标签和属性对照css语法(不区分大小写) JavaScript语法(区分大小
7、写) background background background-attachment background-color background-image background-position background-repeat color color 样式标签和属性对照CSS语法(不区分大小写) display display list-style-type list-style-image list-style-position list-style white-spacebackgroundAttachment backgroundColor backgroundImage ba
8、ckgroundPosition backgroundRepeatJavaScript语法( 区分大小写 )listStyleTypelistStyleImage listStylePosition listStylewhiteSpace文字样式标签和属性对照CSS语法(不区分大小写) font font font-family font-size font-style font-variant font-weightfontFamily fontSize fontStyle fontVariant fontWeight文本标签和属性对照CSS语法(不区分大小写) letter-spacing
9、 line-break line-height text-align text-decoration text-indent text-justify text-transform vertical-alignJavaScript语法( 区分大小写 )JavaScriptletterSpacing lineBreak lineHeight textAligntextDecorationtextIndenttextJustify textTransform verticalAlign语法( 区分大小写 )obj.style 方法,这个方法只能 JS 只能获取写在 html 标签中的写在 styl
10、e 属性 中的值( style=.),看一下代码XML/HTM 代码vtitleJS 获取 CSS属性值 v/title JS 获取 CSS属性值 v/div alert(document.getElementById(css88).style.width);/200px alert(document.getElementById(css88).style.color);/空白和外部方法。上面这个例子对id为css88的div设置了 2种烦事的样式,包括style 样式 class 。从 alert 出来的信息可以看到, document.getElementById(css88).style
11、 法获取不到class为SS的属性和值。那么这么样才能获取到 class 为 ss 的属性和值呢?IE 中使用的是 obj.currentStyle方法,而 FF是用的是 getComputedStyle网上一个比较方法是:XML/HTM 代码vtitleS 获取 CSS属性值 v/title sdf function GetCurrentStyle (obj, prop) if (obj.currentStyle) return obj.currentStyleprop;else if (window.getComputedStyle) propprop = prop.replace (/(A-Z)/g, -$1); propprop = prop.toLowerCase ();return document.defaultView.getComputedStyle (obj,null)prop;return null;var dd=document.getElementById(qq); alert(GetCurrentStyle(dd,width);当然,如果您是引用外部的 css 文件同样适用。另:可以将上面的方法简化为返回最终样式函数,兼容
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- TD/T 1036-2013土地复垦质量控制标准
- TD/T 1015-2007城镇地籍数据库标准
- 地理●广东卷丨2021年广东省普通高中学业水平选择性考试地理试卷及答案
- EDTA标准溶液的配制与标定43课件
- 考研复习-风景园林基础考研试题【黄金题型】附答案详解
- 风景园林基础考研资料试题及答案详解(典优)
- 《风景园林招投标与概预算》试题A附参考答案详解(培优a卷)
- 2025-2026年高校教师资格证之《高等教育法规》通关题库含答案详解(培优)
- 2024年山东华兴机械集团有限责任公司人员招聘笔试备考题库及答案详解1套
- 无锡市2024-2025学年五年级下学期数学期末试题一(有答案)
- 课件:《马克思主义基本原理概论》(23版):第七章 共产主义崇高理想及其最终实现
- 新媒体编辑面试题及答案
- 2025年上海市高考英语热点复习:六选四句子还原之说明文(上)
- 2025年gmp 基础知识培训试题及答案
- 网络空间中的群体行为分析-深度研究
- 软件工程监理实施细则10
- 统计业务培训
- 2025-2030年中国水利工程勘察设计市场运营状况与发展潜力分析报告
- 海康智慧工地解决方案
- 内镜护理安全管理制度
- 数理统计课件:三大分布和分位数
评论
0/150
提交评论