选择颜色后使用js更改div的颜色 [英] change color of div using js after select color
本文介绍了选择颜色后使用js更改div的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi 2 all
i有8个div标签,每个标签都有id a1,下一个有id为a2,第三个有id为a3
等每个都有颜色
我还有我的网站的容器div,其类别
hi 2 all
i have 8 div tags each of them have id a1 and the next have id of a2 and third have id of a3
and so on each have color
and i also have container div for my web site which have class
.pro_wrapper
i需要用户选择a1的div例如更改包装器的颜色我的代码在下面的网站到a1颜色不起作用
i need when user select div of a1 for example change the color of the wrapper of the site to a1 color my code is below didn't work
for(var i=1;i<=8;i++)
{
var color=$("#"+a(i));
$(color).click(function()
{
switch(color)
{
case (i==1):
$(".pro_wrapper").css("background-color","red");
break;
case (i==2):
$(".pro_wrapper").css("background-color","yellow");
break;
}
});
}
请注意我已经写了$(文件).ready line
什么是错的我的代码
note that i already write $(document).ready line
what's wrong with my code
推荐答案
( # + a(i));
("#"+a(i));
(color).click(function()
{
switch (颜色)
{
case (i == 1 ):
(color).click(function() { switch(color) { case (i==1):
( .pro_wrapper).css( background-color, red);
break ;
case (i == 2 ):
(".pro_wrapper").css("background-color","red"); break; case (i==2):
这篇关于选择颜色后使用js更改div的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文