![如何用JS控制CSS基本样式_第1页](http://file2.renrendoc.com/fileroot_temp3/2021-5/12/1062cb97-da43-4daf-9c73-22dd5eb7c206/1062cb97-da43-4daf-9c73-22dd5eb7c2061.gif)
![如何用JS控制CSS基本样式_第2页](http://file2.renrendoc.com/fileroot_temp3/2021-5/12/1062cb97-da43-4daf-9c73-22dd5eb7c206/1062cb97-da43-4daf-9c73-22dd5eb7c2062.gif)
![如何用JS控制CSS基本样式_第3页](http://file2.renrendoc.com/fileroot_temp3/2021-5/12/1062cb97-da43-4daf-9c73-22dd5eb7c206/1062cb97-da43-4daf-9c73-22dd5eb7c2063.gif)
![如何用JS控制CSS基本样式_第4页](http://file2.renrendoc.com/fileroot_temp3/2021-5/12/1062cb97-da43-4daf-9c73-22dd5eb7c206/1062cb97-da43-4daf-9c73-22dd5eb7c2064.gif)
![如何用JS控制CSS基本样式_第5页](http://file2.renrendoc.com/fileroot_temp3/2021-5/12/1062cb97-da43-4daf-9c73-22dd5eb7c206/1062cb97-da43-4daf-9c73-22dd5eb7c2065.gif)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年12月金华事业单位公开招聘金华职业技术大学公开招聘2人笔试历年典型考题(历年真题考点)解题思路附带答案详解
- 2024年12月湖北艺术职业学院公开招聘青年实验艺术团舞蹈演员12人笔试历年典型考题(历年真题考点)解题思路附带答案详解
- 高考语文二轮复习【知识精研】病句的辨析与修改 课件
- 体检市场分析课件
- 《让世界充满爱》课件
- 《内部PK机制》课件
- 恒大大盘暴力售卖模式课件
- 9 枫树上的喜鹊 【知识精研】语文二年级下册统编版
- 《过滤交流材料》课件
- 二零二五年度离婚协议中关于子女抚养费支付的专项合同3篇
- 2024-2025学年七年级数学下册第7章《幂的运算》检测卷(苏科版2024 含答案解析)
- 2025春季开学前学校安全隐患排查工作实施方案:5大安全排查一个都不能少
- 亲子关系断绝协议书范文
- 2024-2025学年教科版八年级物理下册 第12章 机械能 综合素质评价卷(含答案)
- 2024年苏州职业大学高职单招职业适应性测试历年参考题库含答案解析
- (完整版)高考英语词汇3500词(精校版)
- 2024年联勤保障部队第九四〇医院社会招聘笔试真题
- 【人教版化学】选择性必修1 知识点默写小纸条(答案背诵版)
- 00015-英语二自学教程-unit1
- 2024中华人民共和国农村集体经济组织法详细解读课件
- 中小学教师教育法律法规培训PPT页
评论
0/150
提交评论