2017-03-17 8 views
0

img divがタップされたときに警告が追加されました。 1回のタップで複数のアラートが表示されます。 Webインターフェイスでは、時々私は単一の警告を得るが、モバイルでは複数回実行している。タップイベントは最初のタップでは機能していません。それは2番目のタップのために働いています。JQueryアラートポップアップが3回実行されましたが、1回実行されました

<html> 
<body> 
plug:<img id="plug" src="http://icons.iconarchive.com/icons/zeusbox/gartoon/32/socket-icon.png"> 
</body> 
</html> 
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script> 
<script src="https://code.jquery.com/mobile/1.5.0-alpha.1/jquery.mobile-1.5.0-alpha.1.min.js"></script> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/jquery-ui.min.js"></script> 

<script> 
$(document).ready(function(){ 
    $("#plug").on('tap', function() { 
     alert("plese long press"); 
    }); 
}); 
</script> 
+1

なぜあなたのスクリプトは 'html'タグの外ですか? – Laazo

+0

それは問題ですか? – BhanuPrakash

+0

これは不正な形式のドキュメントであるため、一部のブラウザではスクリプトが無視される場合があります。 – Laazo

答えて

0

コンソールでこのエラーが発生しています。

Uncaught TypeError: Cannot read property 'add' of undefined 

i think your JQuery version and JQuery-ui version not compatible. 

change your jquery-ui with this one 

    <script 
     src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" 
     integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" 
     crossorigin="anonymous"></script> 

that should solve the problem 
0

あなたはこれを試みることができる。..

$("#plug").on('tap', function(e) { 
    e.preventDefault(); 
    alert("plese long press"); 
}); 

これによると、それは他人のために働いている:あなたのイベントでjQuery mobile tap event triggered for twice

0

複数回発射イベントを停止するpreventDefault()を追加する:

$("#plug").unbind('tap').on('tap', function(event) { 
    event.preventDefault(); 
    alert("please long press"); 
}); 
+0

もう一度3回呼び出されます。また、タップイベントはモバイル版の2番目のタップで動作しています。 – BhanuPrakash

+0

[OK]をクリックすると、バインドされていないコールがチェーンされますタップイベントのバインディングに追加することができます。 –

関連する問題