禁用右键单击特定的< 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文档