これはデスクトップのサファリで動作しますが、iOSバージョンではアラートがポップアップしません。 iOSの 'html'要素にバインドすることは可能ですか?ユーザーがページ上の他の場所をクリックするたびにドロップダウンメニューを閉じたいと思います。iOSはクリックするとjavascript機能をバインドします<html>
$('html').bind("click", function(){alert("clicked!")})
EDIT
jsfiddleは明らかに私の問題を取り除きますインラインフレームに埋め込ま以来、htmlとしてこれを投稿。このページをデスクトップのSafariで開くとうまく動作しますが、iOSシミュレータではクリックすると何も表示されません。
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('html, body').bind("click", function(){alert("html or body")})
$(document).bind("click", function(){alert("document")})
});
</script>
<body>
</body>
</html>
EDIT 2
また、これはiOSのシミュレータや、私のiPhone上で私のために動作しません。デリゲート()をアプリに入れてリンクをクリックすると、警告が表示されます。
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<body>
</body>
<script type="text/javascript">
$(document).delegate('html, body', "click", function(){alert("html or body")});
</script>
</html>
EDIT 3
これは動作します!
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<body>
<div id="stuff">applesauce</div>
<div>other stuff</div>
</body>
<script type="text/javascript">
$(':not[#stuff]').on("click", function(){alert("not stuff")});
</script>
</html>
代わりに$( 'body')を使用してみましたか? –
なぜ$( 'body')が代わりに機能するのですか?身体を聞くという言葉がどこかありますか? – spike
私は参照を持っていませんが、各デバイスはjavascriptを多少扱いますので、iOSは$( 'html')を多少使い分けるかもしれません。 –