简体   繁体   English

jQuery 解除绑定事件

[英]jQuery unbind event

If I write jQuery code as below;如果我编写如下 jQuery 代码;

$("input:checkbox").unbind("touchstart");

Here touchstart would only be recognized by the iPad.这里touchstart只能被 iPad 识别。 Can this cause an issue on desktop browsers which do not understand touchstart and should I put this piece of code in an if (iPad) block这是否会导致无法理解touchstart桌面浏览器出现问题,我是否应该将这段代码放在 if (iPad) 块中

Also how does jQuery understand "touchstart" even though I could not find any reference to it in the JS library..即使我在 JS 库中找不到任何对它的引用,jQuery 如何理解"touchstart"

You can still unbind an event if the event isn't supported.如果事件不受支持,您仍然可以取消绑定事件。 jQuery doesn't understand touchstart, at least not in the way you expect. jQuery 不理解 touchstart,至少不是您期望的方式。 It just hold a list of handlers in name of 'touchstart' and if you call unbind it'll remove them.它只是以“touchstart”的名义保存一个处理程序列表,如果你调用 unbind 它将删除它们。 If the browser doesn't support touchstart you just won't see the event fired.如果浏览器不支持 touchstart,您将不会看到该事件被触发。

Bear in mind it's one thing to not support touch event and it's another to have no touch device, latest desktop browser do support touch events.请记住,不支持触摸事件是一回事,没有触摸设备是另一回事,最新的桌面浏览器确实支持触摸事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM