如何使用“MyBullets”类更改div的颜色,并使用JQuery中带有“MyNumbers”类的div中的颜色?
像某样的东西。$MyComponent.find(".MyBullets").css("background-color",$thisComp.find(".MyNumbers").css(background-color)....);
答案 0 :(得分:3)
试试这个,
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</script>
<script>
function changeColor() {
var color = $(".MyNumbers").css("background-color");
$(".MyBullets").css("background-color", color);
}
</script>
</head>
<body>
<div class="MyBullets">MyBullets</div>
<div class="MyNumbers" style="background-color:Red";>MyNumbers</div>
<input type="button" value="click here to change color" onclick="changeColor()" />
</html>
答案 1 :(得分:0)
var color = $(".MyNumbers").css("background-color");
$(".MyBullets").css("background-color", color);
答案 2 :(得分:0)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
//Handle Click Event
$("#btn").click(function()
{
var ColorCode= $(".MyNumbers").css('backgroundColor');
$(".MyBullets").css('backgroundColor',ColorCode);
});
});
</script>
<style>
.wrapper { height:150px; width:500px; border:1px solid #e4e4e4; margin:auto; padding:10px;}
.MyNumbers { height:100px; width:240px; background:#06C; float:left;}
.MyBullets { height:100px; width:240px; background:#fff; float:right;}
.btn { margin:10px auto 10px; background:#484848; color:#FFF; height:35px; }
</style>
</head>
<body>
<div class="wrapper">
<div class="MyNumbers"></div>
<div class="MyBullets"></div>
<input type="button" id="btn" value="Change Color" class="btn" />
</div>
</body>
</html>