作者:电脑信息网日期:
返回目录:设置问题
function changeColor(){
var div=document.getElementByID("divID");
div.style.background="#color"; //color自定 自变
}
var timer=setInterval(changeColor,1000); //这是你想zhidao要的自版动变换?每隔1000秒换次颜权色
可以使用js的css方法background-color属性实现点击按钮改变div背景颜色。
具体步骤如下:
需要知准备的材料分别是:电脑、浏览道器、ultraedit。
1、在ue编辑器中回新建一个空白的html文件,css文件答,js文件。
2、在ue编辑器中输入以下html代码。
3、在ue编辑器中输入以下css代码。
4、在ue编辑器中输入以下js代码。
5、编辑完成以后,在ue编辑器中点击保存,格式选择UTF8无BOM。
6、在浏览器中打开此html文件,可以看到最终想要实现的点击按钮改变div背景颜色效果。
首先,把CSS和JS标签e799bee5baa6e79fa5e98193e4b893e5b19e334style属性对照表了解了:
CSS 和 JavaScript 标签 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<script language="javascript">
function validate(){
if (document.all("name").value == ""){
document.all("name").style["borderColor"]="red";//就是这里
return;
}
}
</script>
<BODY>
<input type="text" name="name" >
</BODY>
</HTML>
js所有修改css的方法是
获取dom元素 var xxx=document.querySelector('css选择器')
xxx.style.backgroundColor='颜色';