Onclick在下面的div中显示颜色 [英] Onclick show color in a div below

查看:125
本文介绍了Onclick在下面的div中显示颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个颜色列表,显示在我的网页上一个50像素的方框中。

I have a list of colors which display in a 50px square boxes on my page.

我想要做的是能够点击任何颜色

What i would like to do is be able to click any of the color boxes and then it will show the clicked color in a div below.

<div style="background:#000000; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#c9c9c9; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#737373; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#424242; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#184880; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#3485bf; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#9ad8e6; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#006891; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#0f6769; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#009687; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#79c7c2; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#72b88a; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#669100; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#b5cf8c; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#74750e; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#c7c25f; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#faeb69; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#ffffa8; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#ffc824; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#f5652c; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#f0ab5d; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#e36b10; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#bd3a0f; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#996751; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#78502a; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#c2ae97; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#f4f4f4; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#a31d20; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#d4536c; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#e0d1dc; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#513d7a; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#9178ad; width:50px; height:50px; float: left; margin:4px"></div>
<div style="background:#d6cee0; width:50px; height:50px; float: left; margin:4px"></div>

然后当其中一种颜色被点击时,它会显示在下面

And then when one of the colors is clicked it will display below

<div id="result"></div>


推荐答案

尝试以下代码:

Try below code :

$("div[style]").click(function(){
    $("#result").css("background-color",$(this).css("background-color"));

})

jsFiddle的链接 http://jsfiddle.net/ACaX9/

Link for jsFiddle http://jsfiddle.net/ACaX9/

这篇关于Onclick在下面的div中显示颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆