jQuery单击事件与类的属性

时间:2018-11-02 12:12:19

标签: javascript jquery

我该如何使用class.i编写click事件属性,但它正在调用所有相同的class click事件。如何解决此问题? http://jsfiddle.net/h4JXs/10345/

$(document).on('click', 'a[data-car="blue"].plus', function(e) {
  e.stopImmediatePropagation();
  alert("car blue");
});
$(document).on('click', 'a[data-bike="blue"].plus', function(e) {
  e.stopImmediatePropagation();
  alert("car bike");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a data-car="blue" class="plus">car
</a>

<a data-bike="blue" class="plus">bike
</a>

2 个答案:

答案 0 :(得分:0)

这可能不是最佳解决方案,但是您可以尝试这种方式。

$(document).on('click','.plus').click(function(e){ 
  if($(this).data('car') == 'blue'){
    e.stopImmediatePropagation();
    alert("car blue");
  }  
});  

$(document).on('click','a[data-bike="blue"].plus').click(function(e){ 
  if($(this).data('bike') == 'blue')  {
    e.stopImmediatePropagation();
    alert("car bike");
  }
});

答案 1 :(得分:0)

选择我的JSFiddle也许可以为您提供帮助。

JS代码-

def Contrast_enhancement(img):
    newimg = img
    height = img.shape[0]
    width = img.shape[1]
    for i in range(height):
       for j in range(width):
           if(img[i][j] * 255 >= 0 and img[i][j] * 255 <= 100):
               newimg[i][j] = (((3/2) * (img[i][j] * 255)) + 50)/255
    return newimg
相关问题