gpt4 book ai didi

javascript - 关于 $(document).bind() 的问题

转载 作者:行者123 更新时间:2023-12-02 20:10:21 26 4
gpt4 key购买 nike

我在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com