这听起来可能是一个非常愚蠢的问题,但它让我疯狂。我有div
我要追加touchevent
。我就是这样做的:
$("#superContainer").bind('touchstart', function(event, passedName) {
alert("touch start");
//[more code]
});
这种方法不起作用。没有警报,没有。 div
#supercontainer
的属性为width: 100%; top: 0px
。
以下方法有效:
$(window).bind('touchstart', function(event, passedName) {
alert("touch start");
//[more code]
});
但我想避免将整个窗口绑定到事件。我正在使用最新版本的jQuery。
答案 0 :(得分:1)
根据http://api.jquery.com/jQuery/,你应该使用
$(function() {
// Document is ready
});
或
jQuery(function( $ ) {
// Document is ready
});
在这种情况下哪个是问题
同时使用.on
代替.bind
:
从jQuery 1.7开始,.on()方法是将事件处理程序附加到文档的首选方法。 https://api.jquery.com/bind/