js按钮改变背景颜色(js设置按钮背景颜色)
js修改背景颜色
可以加上id属性例如:
div id="div" style="width:100px; height:100px"ssss/div
script
var d = document.getElementById("div");
d.style.backgroundColor = "red";
/script

js实现五个按钮,点击每个按钮屏幕背景变成特定的每个颜色(红黄粉绿蓝)
!DOCTYPE?html
html?lang="en"
head
meta?charset="UTF-8"
titleDocument/title
/head
body
button?onclick="color('red')"red/button
button?onclick="color('yellow')"yellow/button
button?onclick="color('pink')"pink/button
button?onclick="color('green')"green/button
button?onclick="color('blue')"blue/button
/body
script?type="text/javascript"
function?color?(c)?{
document.body.style.backgroundColor=c;
}
/script
/html
js 改变div 里面的某个文字的颜色
1、新建一个html文件,命名为test.html。
2、在test.html文件内,创建一个div模块,设置其class属性为bg,id属性为mydiv,用于下面设置css样式和获取div对象。
3、在test.html文件内,使用css设置div的样式,设置其宽度为500px,高度为272px,背景图片为2.jpg。
4、在test.html文件内,在div的下面创建一个button按钮,按钮名称为“更换背景颜色”。
5、给button按钮绑定onclick点击事件,当按钮被点击时,执行myfun()函数。
6、在test.html文件内,在js标签内,创建myfun()函数,在函数内,使用getElementById()方法通过id获得div对象,设置对象中的backgroundImage背景属性为另一张图片,从而实现改变div的背景图片。就完成了,运行就可以了。
如何用js实现点击按钮改变表格中的一个单元格的背景颜色
script language="javascript" type="text/javascript"
function chgbg(id){
var obj=window.document.getElementById(id);
var bg=obj.style.backgroundColor;
if(bg=='') obj.style.backgroundColor='#f00'
else obj.style.backgroundColor=''
}
/script
table width="100%" border="1" cellspacing="0" cellpadding="4"
tr
td id="td1" /td
td id="td2" /td
td id="td3" /td
/tr
tr
td id="td4" /td
td id="td5" /td
td id="td6" /td
/tr
/table
input type="button" value="点击改变指定单元格背景" onClick="chgbg('td1');" /
JavaScript中怎么设置一个按钮,然后点击一次这个按钮,整个背景颜色就变一下,红黄蓝依次变
1、html代码:
button?onclick='demo()'click?me!/button
2、js代码:
var?index=0;
function?demo(){
??var?colorArr=['red','yellow','blue'];
??event.target.style.backgroundColor?=?colorArr[index%3];
??index+=1;
}