我们如何防止JavaScript中的默认操作? [英] How do we prevent default actions in JavaScript?

查看:111
本文介绍了我们如何防止JavaScript中的默认操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是跨浏览器方法?我需要阻止对图像的任何默认操作,这样在默认基础上都不会触发拖动或其他任何操作。

What is the cross-browser method? I need to prevent any default action on an image, so that neither dragging nor anything else will fire on a default bases.

推荐答案

您可以注册要取消的事件,然后从它们注册 return false 或使用 Event.preventDefault() ,取决于浏览器和事件。

You can register the events you want to cancel, and then either return false from them or use Event.preventDefault(), depending on the browser and event.

这篇关于我们如何防止JavaScript中的默认操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆