我想创建类似像素艺术记事本的东西,但当我按下它们并将此值赋给变量时,我无法从我的div(左上角)获得背景颜色,然后将此值分配给"当前颜色" div(右上角)。 The screenshot of my app
我的代码:
$(document).ready(function() {
createGrid(16);
$('#newGrid').click(function() {
refreshGrid();
});
$('.colorBoxes').click(function() {
var currentObject = event.target;
console.log(currentObject);
//here i'm trying to get the color of my clicked div
//(I'm really have no idea what to do)
variable = window.getComputedStyle(currentObject);
var containerForBackgroundColor = variable.getPropertyValue('background-color');
console.log(containerForBackgroundColor);
});
});
答案 0 :(得分:0)
当您使用jQuery时,可以使用以下代码访问background-color:
var containerForBackgroundColor = $(this).css('background-color');