Javascript 禁用右键单击特定<;部门>;或类="&引用;
这是我的示例代码: htmlJavascript 禁用右键单击特定<;部门>;或类="&引用;,javascript,jquery,Javascript,Jquery,这是我的示例代码: 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>
<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;">
我不希望任何人能够右键单击第一张图片(手机),但除此之外(键盘)应该能够右键单击
PS:我知道这可以被浏览器覆盖,但没关系:)想出了一个解决方案
$('.tlClogo').bind('contextmenu', function(e) {
return false;
});
小提琴:
编辑1:只有第一个现在不能右键单击
<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>
这是手机,任何人都不能右键单击它!>:)
这是键盘,当然你可以右键点击:)
$('.tlClogo').bind('contextmenu',函数(e){
返回false;
});
编辑2:提供HTML文档一些浏览器?它可以被所有浏览器覆盖。您的代码工作正常。您只是忘记了在FIDLE中导入jquery库(在“框架和扩展”菜单下)。查看我的更新,我知道,但它不起我要找的功能:)
<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>