javascript - 需要有关鼠标按下所选图像的背景颜色的帮助。并删除所选其他图像的背景

标签 javascript jquery html css

//这使我在 img 上的背景颜色为黄色,但如果我选择另一个 img,它将不会删除第一个选择的 img 上的背景颜色:

$('img').mousedown(function() {
    var $selectedDiv = $(this).parent();
    var divId = $selectedDiv.attr('id');
    currentCol = divId [1];
    currentRow = divId [3];
    $("#r"+currentCol+"c"+currentRow).css("background", "Yellow");
});

最佳答案

这就是我要做的:

$('img').mousedown(function() {
    $('img').css('background', ''); // This will set back the background colour to whatever colour you need image to be.
    // You can now process the current image.
    var $selectedDiv = $(this).parent();
    var divId = $selectedDiv.attr('id');
    currentCol = divId [1];
    currentRow = divId [3];
    $("#r"+currentCol+"c"+currentRow).css("background", "Yellow");
});

关于javascript - 需要有关鼠标按下所选图像的背景颜色的帮助。并删除所选其他图像的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26741510/

相关文章:

javascript - 为什么我的 javascript 按钮点击不起作用?

javascript - 如何使用jquery知道选择了哪个数字选项

javascript - Jquery/JavaScript : How to append the data by column dynamically to each row in jquery?

javascript - 如何减少并改进丑陋的 JavaScript 代码?

javascript - 使用条形码扫描仪将焦点从一个输入更改为下一个输入

javascript - 单击时展开和收缩的垂直 div

javascript - 背景全屏视频

javascript - 为什么我的数组在洗牌时没有被重新分配?

jquery - 当 TBody tr 为空时移除 TFoot

php - 使用 POST PHP 未从输入字段传递整个值