gpt4 book ai didi

javascript - jQuery隐藏div函数

转载 作者:行者123 更新时间:2023-11-30 06:01:11 30 4
gpt4 key购买 nike

是否有任何功能可以在右键单击时隐藏“DIV”或其他 html 元素,一些教程、脚本、简单代码 javascript 或 jquery。示例:何时单击链接或

标记或“li”或“Ul”或“a”并右键单击以隐藏此元素...如何操作?

更新:是的,您所有的解决方案都可以,但请查看此代码以及为什么不起作用:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<script>
$(document).on("mousedown", "div, img, span, a", function () {
if (event.which === 3)
$(this).hide();
});
</script>

<?php

$url = 'http://www.kupime.com/';

$data = file_get_contents($url);

$data = '<head><base href='.$url.' target="_blank" /></head>'.$data;




echo $data;


?>

当我点击时没有任何反应。为什么?

最佳答案

您可以在 mousedown 处理程序中使用 event.which 来推测用户是用鼠标左键还是右键单击。

$(document).on("mousedown", "div", function() { 
if (event.which === 3)
$(this).hide();
});

参见 this answer有关 event.which

的更多信息

编辑

当然,如果你想隐藏除 div 之外的元素,你可以在 on 的选择器中用逗号分隔它们

$(document).on("mousedown", "div, img, span, a", function () { 
if (event.which === 3)
$(this).hide();
});

或者,如果您想隐藏右键单击的任何内容

$(document).on("mousedown", "*", function () { 
if (event.which === 3)
$(this).hide();
});

关于javascript - jQuery隐藏div函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8491617/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com