2016-08-12 4 views
1

を働いていない私は、から物事の全体の束を試してみました:しかし、何も動いていないようにみえ
onClick not working on mobile (touch)ボタンのonClickモバイルデバイス上

document .click function for touch device

。私は間違って何をしているのかもしれない

#modal-close {cursor:pointer;} 

<button class="button" id="modal-close">ok</button> 

function hideModal(){ 
    var modal = document.getElementById('modal'); 
    modal.style.display = 'none'; 
} 

$(function() { 
     $('#modal-close').on('click touchstart',function (e) { 
      hideModal(); 
      }) 
     }); 

:ここ

は、私が持っている何ですか?

+0

使用し、この '$(' #モーダル-近い ')(touchstartをクリック '機能(){ hideModal();} )' オン。' 私は、IOS上でこの問題を見てきました –

+0

。クリックイベントをトリガーするのではなく、タッチがトリガーホバー状態をトリガーします。私はこの問題を解決するためにこれを使用したと信じています: –

+0

@RashidJavedは動作しません –

答えて

-1

は私を得たもので、有効な

たクラスを追加または削除するclassListを使用hideModal()ました。私はそれをclassName +=に切り替えました。

0

ボタンのidをmodal_closeに変更します。これはあなたのために働くかもしれません。 id値は識別子のように動作するため、識別子に名前を付けるためにすべてのシンボルを使用することはできません。

#modal-close {cursor:pointer;} 

<button class="button" id="modal-close">ok</button> 

function hideModal(){ 
    var modal = document.getElementById('modal'); 
    modal.style.display = 'none'; 
} 

$(function() { 
     $('#modal-close').on('click touchstart',function (e) { 
      hideModal(); 
      }) 
     }); 

判明

+0

これは動作しませんでした。 –

関連する問題