我在 iPad 上有一个页面。 如何获取被触摸的特定元素而不是通用容器元素?
$(document).bind("touchstart",function(e){
console.log("touchstart on target : " + e.target.id);
}
最佳答案
尝试使用委托(delegate)
代替
$(function() {
$(document).delegate('div', 'click', function(event) {
alert($(this).attr('id'));
// To prevent Propagation
event.stopPropagation()
});
});
实际操作:http://jsfiddle.net/xem65/
(使用点击,因为我在 atm 附近没有任何触摸设备)
委托(delegate)文档:http://api.jquery.com/delegate/
关于javascript - 关于 $(document).bind() 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7010657/