禁用右键单击特定的< div>或class =“" [英] Disable right click on specific <div> or class=""
本文介绍了禁用右键单击特定的< div>或class =“"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的示例代码:
html
<div>
This is the Phone and NO ONE SHOULD RIGHT CLICK THIS! >:) </br>
<img class="tlClogo" src="http://i.imgur.com/0atiS5C.jpg" style="height: 120px; width:120px;">
</div></br></br></br></br>
And this is the Keyboard, ofcourse yo can right click this :)</br>
<img src="http://i.imgur.com/xkrKz1X.jpg" style="height: 120px; width:120px;">
js
$('img').bind('contextmenu', function(e){
alert("This Logo is protected");return false;
});
我希望没有人能够右键单击第一张图片(手机),但除了那个(键盘)之外,还应该能够右键单击.
I want no one to be able to right click the 1st picture (cellphone) but other than that(keyboard) should be able to right click.
PS:我知道可以被浏览器覆盖,但没关系:)
PS: I know this can be overriden by browsers but its okay :)
推荐答案
提出解决方案.
$('.tlClogo').bind('contextmenu', function(e) {
return false;
});
提琴: http://jsfiddle.net/79k52rvu/4/
现在只有第一个不可右键单击!
EDIT 1: Only the first one is now NOT right-clickable!
<html>
<body>
<div>
This is the Phone and NO ONE SHOULD RIGHT CLICK THIS! >:) </br>
<img class="tlClogo" src="http://i.imgur.com/0atiS5C.jpg" style="height: 120px; width:120px;">
</div>
</br></br></br></br>
And this is the Keyboard, ofcourse yo can right click this :)</br>
<img src="http://i.imgur.com/xkrKz1X.jpg" style="height: 120px; width:120px;">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$('.tlClogo').bind('contextmenu', function(e) {
return false;
});
</script>
</body>
</html>
提供了HTML文档
这篇关于禁用右键单击特定的< div>或class =“"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文