2014-11-04 72 views
0

//这给了我的背景色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"); 
}); 
+1

请发布您的HTML的例子。 – 2014-11-04 17:43:48

回答

0

这是我会做什么:

$('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"); 
}); 
+0

请注意,如果你只是想删除一个属性,'$('img').css('background','');'将删除这个特殊的'background'属性。 – 2014-11-04 17:46:36

+0

编辑:) – Nico 2014-11-04 17:47:28

+0

虽然我会用JQuery的'siblings()'方法去。正因如此,OP不会拍得太大。 – 2014-11-04 17:48:47

0

怎么样简单的

$('img').mousedown(function() {....}); 

取代
$('img').mouseover(function() {....}); 

我认为应该解决您的问题。