2017-04-11 34 views
0

有關平板電腦上的點按事件不能像在下面的示例中單擊桌面上的方式那樣工作的任何想法? 在div中點擊類pq時,div應該變成紅色,並在類pq外點擊div時,所有具有pq類的div應該變成白色。點擊平板電腦爲什麼在jquery上的平板電腦上不點按事件工作

<div class="pq"> 
paragraph1 
</div> 
<div class="pq"> 
paragraph2 
</div> 
<div class="pq"> 
paragraph3 
</div> 

<script src="https://code.jquery.com/jquery-3.2.1.js"></script> 


$(document).click(function (e) { 
     $('.pq').css("background-color", "white"); 
     if ($(e.target).hasClass("pq")) { 
       $(e.target).css("background-color", "red"); 
      } 
    }); 




$(document).tap(function (e) { 
     $('.pq').css("background-color", "white"); 
     if ($(e.target).hasClass("pq")) { 
       $(e.target).css("background-color", "red"); 
      } 
    }); 

在桌面上的作品,但用自來水犯規同樣的邏輯可以在這裏運行例如:https://jsfiddle.net/f2j7g92d/

+0

我覺得你需要jQuery手機的tap事件,即使如此,你也不能直接將它定義爲click。 [鏈接](https://api.jquerymobile.com/tap/) –

+0

感謝Ace,我添加了但仍然無效 –

+0

@AnnaHmd請記住確保URL是正確的。 – evolutionxbox

回答

0

嘗試包括這樣的:如果

<link rel="stylesheet" href="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"><script src="//code.jquery.com/jquery-1.10.2.min.js"></script> <script src="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

到腳本,它仍然不起作用我建議你到this網站。

相關問題