javascript修改CSS

来源:互联网 发布:java 获取post还是get 编辑:程序博客网 时间:2024/06/04 08:47

1.js修改单个元素的css属性    

document.getElementByIdx('obj').className=”…”,

document.getElementByIdx('obj').style.backgroundColor=”#003366″,

2.js修改整个页面的css属性     

<link rel = "stylesheet"type="text/css" id="css" href="firefox.css"/>
<spanon click="javascript:document.getElementByIdx('css').href ='ie.css'"></span>

3.js和css的style属性对照表

盒子标签和属性对照
CSS语法 (不区分大小写) JavaScript语法 (区分大小写)
border border
border-bottom borderBottom
border-bottom-color borderBottomColor
border-bottom-style borderBottomStyle
border-bottom-width borderBottomWidth
border-color borderColor
border-left borderLeft
border-left-color borderLeftColor
border-left-style borderLeftStyle
border-left-width borderLeftWidth
border-right borderRight
border-right-color borderRightColor
border-right-style borderRightStyle
border-right-width borderRightWidth
border-style borderStyle
border-top borderTop
border-top-color borderTopColor
border-top-style borderTopStyle
border-top-width borderTopWidth
border-width borderWidth
clear clear
float floatStyle
margin margin
margin-bottom marginBottom
margin-left marginLeft
margin-right marginRight
margin-top marginTop
padding padding
padding-bottom paddingBottom
padding-left paddingLeft
padding-right paddingRight
padding-top paddingTop
 
颜色和背景标签和属性对照
CSS语法 (不区分大小写) JavaScript语法 (区分大小写)
background background
background-attachment backgroundAttachment
background-color backgroundColor
background-image backgroundImage
background-position backgroundPosition
background-repeat backgroundRepeat
color color
 
样式标签和属性对照
CSS语法 (不区分大小写) JavaScript语法 (区分大小写)
display display
list-style-type listStyleType
list-style-image listStyleImage
list-style-position listStylePosition
list-style listStyle
white-space whiteSpace
 
文字样式标签和属性对照
CSS语法 (不区分大小写) JavaScript语法 (区分大小写)
font font
font-family fontFamily
font-size fontSize
font-style fontStyle
font-variant fontVariant
font-weight fontWeight
 
文本标签和属性对照
CSS语法 (不区分大小写) JavaScript语法 (区分大小写)
letter-spacing letterSpacing
line-break lineBreak
line-height lineHeight
text-align textAlign
text-decoration textDecoration
text-indent textIndent
text-justify textJustify
text-transform textTransform
vertical-align verticalAlign

4.引起css改变的js事件

HTML 4.0 的新特性之一是有能力使 HTML事件触发浏览器中的动作(action),比如当用户点击某个 HTML 元素时启动一段JavaScript。下面是一个属性列表,这些属性可插入 HTML 标签来定义事件动作。

FF: Firefox, N:Netscape, IE: Internet Explorer

 

属性当以下情况发生时,出现此事件FFNIEonabort图像加载被中断134onblur元素失去焦点123onchange用户改变域的内容123onclick鼠标点击某个对象123ondblclick鼠标双击某个对象144onerror当加载文档或图像时发生某个错误134onfocus元素获得焦点123onkeydown某个键盘的键被按下143onkeypress某个键盘的键被按下或按住143onkeyup某个键盘的键被松开143onload某个页面或图像被完成加载123onmousedown某个鼠标按键被按下144onmousemove鼠标被移动163onmouseout鼠标从某元素移开144onmouseover鼠标被移到某元素之上123onmouseup某个鼠标按键被松开144onreset重置按钮被点击134onresize窗口或框架被调整尺寸144onselect文本被选定123onsubmit提交按钮被点击123onunload用户退出页面123
0 0