function changeBgColor(element) {
alert(element.style.backgroundColor.value);
if(element.style.backgroundColor == "#123456") {
element.style.backgroundColor = "#111111";
} else {
element.style.backgroundColor = "#222222";
}
}aler()出的值为undefined 请问大虾 我改如何用JavaScript判断这个element在css中的backgroundColor值呢?
谢谢~~
alert(element.style.backgroundColor.value);
if(element.style.backgroundColor == "#123456") {
element.style.backgroundColor = "#111111";
} else {
element.style.backgroundColor = "#222222";
}
}aler()出的值为undefined 请问大虾 我改如何用JavaScript判断这个element在css中的backgroundColor值呢?
谢谢~~
alert(element.style.backgroundColor);这样可以吗,不加value,我这边可以!
if(element.style.backgroundColor == "#123456") {
element.style.backgroundColor = "#111111";
} else {
element.style.backgroundColor = "#222222";
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script type= "text/javascript" src= "jquery-1.2.6.js"> </script>
<script type= "text/javascript">
$(function(){
$("#ch").click(function(){
alert($(this).css("background-color"));
if($(this).css("background-color")=="#123456"){
$(this).css("background-color","#111111")
}else{
$(this).css("background-color","#222222")
}
});
}) function changeBgColor(element) {
alert(element.style.backgroundColor);
if(element.style.backgroundColor == "#123456") {
element.style.backgroundColor = "#111111";
} else {
element.style.backgroundColor = "#222222";
}
} </script>
</HEAD> <BODY>
<input id="ch" type="button" style="background-color:#123456;" value="changeColorJquery"/>
<input id="ch" type="button" style="background-color:#120000;" value="changeColorJS" onclick="changeBgColor(this)"/>
</BODY>
</HTML>
http://www.javascripter.net/faq/rgbtohex.htm
去掉。value