我有一个颜色列表,显示在我页面上的 50 像素方框中。
我想做的是能够单击任何颜色框,然后它将在下面的 div 中显示单击的颜色。
<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>
然后当其中一种颜色被点击时它会显示在下方
<div id="result"></div>
最佳答案
试试下面的代码:
$("div[style]").click(function(){
$("#result").css("background-color",$(this).css("background-color"));
})
jsFiddle 链接 http://jsfiddle.net/ACaX9/
关于javascript - onclick 在下面的 div 中显示颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15070845/