javascript - 禁止从 HTML 页面拖动图像

标签 javascript jquery html css image

我需要在我的页面中放置一张图片。我想禁用该图像的拖动。我正在尝试很多事情,但没有帮助。有人可以帮帮我吗?

我不想将该图像保留为背景图像,因为我正在调整图像大小。

最佳答案

你可以喜欢这个...

document.getElementById('my-image').ondragstart = function() { return false; };

See it working (or not working, rather)

看来你正在使用 jQuery。

$('img').on('dragstart', function(event) { event.preventDefault(); });

关于javascript - 禁止从 HTML 页面拖动图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4211909/

相关文章:

javascript - 在 anchor 标记 onclick 事件中传递参数

javascript - jQuery 使用 .removeClass() 和 .addClass() 切换类无法正常工作

javascript - Google Map API V3 检测容器宽度/高度变化

jquery - 在jquery和javascript中删除json数组中的所有元素

javascript - 没有给定json值时如何显示警告框

php - jQuery .ajax : How to handle Custom Validation Error Message, REST API,400 状态代码?

html - 将背景颜色应用于 .row 类的嵌套元素的问题 - Zurb 基础 css 框架

javascript - 关于轴上标签的问题

html - 在网页中嵌入 SSRS 报告查看器

javascript - 在 div 的所有子级中搜索文本并隐藏不包含它的文本