点击并点击按住操作在移动 Phone / Firefox 移动测试器中不起作用

Tap and Tap Hold Action not working in Mobile Phone / Firefox Mobile Tester

我想在 shopify 中更改鼠标点击或按住的元素的不透明度,但它似乎不起作用。我添加了阻止默认值,因为 grid-product__link 是 link <a href="url" class="grid-product__link is a link">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>    
<script>      
  $(document).ready(function() {        
  $('grid-product__link').on('taphold',function(event){
    event.preventDefault;
     $('.grid-product__secondary-image').css('opacity','1');
    });
    
   $('grid-product__link').on('tap',function(event){
    event.preventDefault;
      $('.grid-product__secondary-image').css('opacity','1');
    });   
  });      
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-mobile/1.4.1/jquery.mobile.min.js"></script>

event.preventDefault 是一个函数。您只是在代码中将其作为值而不是 运行 引用。

而不是,

event.preventDefault;

你应该这样做:

event.preventDefault();