javascript修改CSS
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
属性 | 当以下情况发生时,出现此事件 | FF | N | IE |
---|---|---|---|---|
onabort | 图像加载被中断 | 1 | 3 | 4 |
onblur | 元素失去焦点 | 1 | 2 | 3 |
onchange | 用户改变域的内容 | 1 | 2 | 3 |
onclick | 鼠标点击某个对象 | 1 | 2 | 3 |
ondblclick | 鼠标双击某个对象 | 1 | 4 | 4 |
onerror | 当加载文档或图像时发生某个错误 | 1 | 3 | 4 |
onfocus | 元素获得焦点 | 1 | 2 | 3 |
onkeydown | 某个键盘的键被按下 | 1 | 4 | 3 |
onkeypress | 某个键盘的键被按下或按住 | 1 | 4 | 3 |
onkeyup | 某个键盘的键被松开 | 1 | 4 | 3 |
onload | 某个页面或图像被完成加载 | 1 | 2 | 3 |
onmousedown | 某个鼠标按键被按下 | 1 | 4 | 4 |
onmousemove | 鼠标被移动 | 1 | 6 | 3 |
onmouseout | 鼠标从某元素移开 | 1 | 4 | 4 |
onmouseover | 鼠标被移到某元素之上 | 1 | 2 | 3 |
onmouseup | 某个鼠标按键被松开 | 1 | 4 | 4 |
onreset | 重置按钮被点击 | 1 | 3 | 4 |
onresize | 窗口或框架被调整尺寸 | 1 | 4 | 4 |
onselect | 文本被选定 | 1 | 2 | 3 |
onsubmit | 提交按钮被点击 | 1 | 2 | 3 |
onunload | 用户退出页面 | 1 | 2 | 3 |
javascript修改CSS相关推荐
- JavaScript修改Css样式
在JS中操作CSS属性命名上的区别 以前css直接写死在html中,现在可以通过js脚本去动态修改一个标签的样式. CSS中写法 JS中的写法 说明 color color 一个单词的样式写法是相同 ...
- Vue中动态使用JavaScript修改CSS样式
文章目录 前言 一.实现目标效果的难点 二.使用Computed配合CSS变量完成动态修改CSS 1.设置Computed属性以及slider行内属性 2. 设置css样式(这里使用的是原生css,l ...
- HTML:三种方法用JavaScript修改CSS样式
修改元素的css样式一般是标签的style属性中或头部的style标签中进行增删与修改. 下为利用JS修改元素的css样式的三种较为实用的方式. 第一种:获取相应标签对应的 javascript对象. ...
- JavaScript修改css中style,classname,cssText实例
一.局部改变样式 分为改变直接样式,改变className和改变cssText三种.需要注意的是: 注意大小写: javascript对大小写十分敏感,className不能够把"N& ...
- html5 js 修改css样式,JavaScript修改css样式style_javascript技巧_脚本之家
一.局部改变样式 分为改变直接样式,改变className和改变cssText三种.需要注意的是: 注意大小写: javascript对大小写十分敏感,className不能够把"N&quo ...
- html通过id设置css样式,JavaScript修改style,id,class等css属性样式方法总结
JavaScript允许你即时的改变CSS样式,这样就可以将用户的眼球吸引到你想他们关注的地方上,并且提供较好的交互体验给力 . JavaScript修改CSS有4种方法: 修改节点style(内联样 ...
- js函数改变html样式,JavaScript改变CSS样式的方法汇总
JavaScript允许你即时的改变CSS样式,这样就可以将用户的眼球吸引到你想他们关注的地方上,并且提供较好的交互体验给力 . JavaScript修改CSS有4种方法: 修改节点style(内联样 ...
- html css廖雪峰,廖雪峰js教程笔记12 用DOM更新 innerHMTL 和修改css样式(示例代码)
拿到一个DOM节点后,我们可以对它进行更新. 可以直接修改节点的文本,方法有两种: 一种是修改innerHTML属性,这个方式非常强大,不但可以修改一个DOM节点的文本内容,还可以直接通过HTML片段 ...
- javascript 动态修改css样式
方法一:改变外联css文件,这里不讲这个. 方法二:通过改变claaName来改变样式,语法: obj.className = "style2";//或者 obj.setAttri ...
最新文章
- 华硕p8b75v主板说明书_主板如何接线
- 达梦数据库的基本使用
- 计算机动漫设计VR主要学什么,动漫设计专业学什么 要学什么软件
- postgresql 备份恢复(一)
- 自动化测试工具selenium使用介绍
- 说说 C# 9 新特性的实际运用
- 包含6大数据领域,531个知识点,这张数字化图谱,分享给你
- 分布式协议学习笔记(一) Raft 选举
- 移动磁盘此卷不包含可识别的文件系统要怎么找到数据
- node 更新_更新应用时,如何实现 K8s 零中断滚动更新?
- 如何将EXCEL中的多个单元格内容合并在一个单元格内
- AutoCAD文档01——安装教程
- 风行python_Python曾是程序员的“瑞士军刀”,而如今正被慢慢取代
- 局域网内固定自己的ip
- 微型计算机3月2017,2017年3月计算机一级基础及MSOffice强化习题
- 使用python把批量xls文件转换为xlsx
- nagios NSCA 被动检测
- 降噪蓝牙耳机哪个好?2021主流蓝牙耳机当选降噪耳机
- 边缘检测之Robert算子
- pandas 之 to_csv 保存数据出现中文乱码问题及解决办法