【问题标题】:jQuery hide - div's,p,a,li, etcjQuery 隐藏 - div、p、a、li 等
【发布时间】:2011-12-13 19:10:17
【问题描述】:

我有这个代码和 jquery 函数,用于在按右键时隐藏 HTML 元素,但为什么不起作用?

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<script>
$(document).on("mousedown", "div, p, 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;

?>

【问题讨论】:

    标签: php javascript jquery file-get-contents


    【解决方案1】:

    您缺少 param 事件,而且您使用的是 jQuery 1.3.2,它还没有 .on 函数,您至少需要 1.7。

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
    <script>
    $(document).on("mousedown", "div, p, img, span, a", function (event) { 
        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;
    
    ?>
    

    请修改此列表:

    Failed to load resource: the server responded with a status of 404 (Not Found)
    http://pluspon.com/css/css_style.aspFailed to load resource: the server responded with a status of 404 (Not Found)
    http://pluspon.com/css/fb_css_style.cssFailed to load resource: the server responded with a status of 404 (Not Found)
    http://pluspon.com/scripts/jquery-1.4.2.min.jsFailed to load resource: the server responded with a status of 404 (Not Found)
    http://pluspon.com/scripts/swfobject.jsFailed to load resource: the server responded with a status of 404 (Not Found)
    http://pluspon.com/scripts/countdown/jquery.countdown.jsFailed to load resource: the server responded with a status of 404 (Not Found)
    http://pluspon.com/scripts/lightbox/js/jquery.lightbox-0.5.min.jsFailed to load resource: the server responded with a status of 404 (Not Found)
    http://pluspon.com/scripts/jqtransform/jqtransform.cssFailed to load resource: the server responded with a status of 404 (Not Found)
    http://pluspon.com/scripts/lightbox/css/jquery.lightbox-0.5.cssFailed to load resource: the server responded with a status of 404 (Not Found)
    http://pluspon.com/scripts/jqtransform/jquery.jqtransform.jsFailed to load resource: the server responded with a status of 404 (Not Found)
    GET http://pluspon.com/upload/kupime_world/bosna_flag.jpg 404 (Not Found)
    GET http://pluspon.com/upload/kupime_world/srb_113359.gif 404 (Not Found)
    GET http://pluspon.com/images/rs/logo_small.png 404 (Not Found)
    GET http://pluspon.com/upload/kupime_world/slo_113425.gif 404 (Not Found)
    GET http://pluspon.com/upload/oglas/mala_2_235532.jpg.axd?width=204&height=140&crop=auto 404 (Not Found)
    GET http://pluspon.com/upload/oglas/gal1_17290.jpg.axd?width=144&height=96&crop=auto 404 (Not Found)
    GET http://pluspon.com/upload/oglas/mala_2_16323.jpg.axd?width=204&height=140&crop=auto 404 (Not Found)
    GET http://pluspon.com/upload/site_banners/kako_funkcionise_kupime_142020.png 404 (Not Found)
    GET http://pluspon.com/upload/oglas/mala_1_172429.jpg.axd?width=204&height=140&crop=auto 404 (Not Found)
    GET http://pluspon.com/upload/site_banners/kupime_com_nacin_placanja11_164124.png 404 (Not Found)
    GET http://pluspon.com/upload/site_banners/kupime-home-desni-box-srbija_123628.png 404 (Not Found)
    GET http://pluspon.com/upload/oglas/mala_0841.jpg.axd?width=204&height=140&crop=auto 404 (Not Found)
    GET http://pluspon.com/images/rs/logo_programa.gif 404 (Not Found)
    GET http://pluspon.com/upload/oglas/gal_2_172910.jpg.axd?width=144&height=96&crop=auto 404 (Not Found)
    GET http://pluspon.com/upload/oglas/glavna_1_173127.jpg.axd?width=441 404 (Not Found)
    GET http://pluspon.com/upload/oglas/mala_103623.jpg.axd?width=204&height=140&crop=auto 404 (Not Found)
    GET http://pluspon.com/upload/oglas/mala_191212.jpg.axd?width=204&height=140&crop=auto 404 (Not Found)
    GET http://pluspon.com/upload/oglas/mala_174731.jpg.axd?width=204&height=140&crop=auto 404 (Not Found)
    GET http://pluspon.com/upload/kupime_world/hun_133823.gif 404 (Not Found)
    GET http://pluspon.com/upload/oglas/mala_03932.jpg.axd?width=204&height=140&crop=auto 404 (Not Found)
    GET http://pluspon.com/upload/kupime_world/cro_113411.gif 404 (Not Found)
    GET http://pluspon.com/images/scrollHeadLetterTop.png 404 (Not Found)
    GET http://pluspon.com/upload/oglas/gal_3_172929.jpg.axd?width=144&height=96&crop=auto 404 (Not Found)
    GET http://pluspon.com/upload/oglas/mala_st_171818.jpg.axd?width=204&height=140&crop=auto 404 (Not Found)
    GET http://pluspon.com/upload/oglas/mala_1_175010.jpg.axd?width=204&height=140&crop=auto 404 (Not Found)
    GET http://pluspon.com/images/rss.png 404 (Not Found)
    GET http://pluspon.com/upload/oglas/mala_1_231525.jpg.axd?width=204&height=140&crop=auto 404 (Not Found)
    GET http://pluspon.com/upload/oglas/mala_231142.jpg.axd?width=204&height=140&crop=auto 404 (Not Found)
    GET http://pluspon.com/images/fb.png 404 (Not Found)
    GET http://pluspon.com/images/twitter.png 404 (Not Found)
    GET http://pluspon.com/upload/oglas/mala_235111.jpg.axd?width=204&height=140&crop=auto 404 (Not Found)
    GET http://www.kupime.com/images/logo.png.axd?width=193&height=154 404 (Not Found)
    XMLHttpRequest cannot load http://www.kupime.com/index.asp?cmd=get_offer_coupons&offer_id=954. Origin http://pluspon.com is not allowed by Access-Control-Allow-Origin.
    

    【讨论】:

    • 您应该更新您的代码以向我们展示您的尝试。我访问了您的链接,但弹出窗口不允许我尝试任何操作。
    • 是的,但是这个弹出窗口是一个 Div,右键单击它们必须隐藏!
    • 但我使用的是 用 $url 更改 pluspon 域 - 为此。
    • 好的,我看到了,但是如何解决呢?
    • 我认为基本标签可以解决这个问题,但似乎不太好
    【解决方案2】:

    我相信你的语法是关闭的,api.jquery.com/mousedown .mousedown() 事件。尝试通过 $('div, p, img, span, a').mousedown(function(){}); 选择元素

    您还在“mousedown”函数中引用事件,其中未定义事件。

    $('div, p, img, span, a').mousedown(function()
    {
        $(this).hide();
    })
    

    并重新展示。

    $('div, p, img, span, a').mouseup(function()
    {
        $(this).show();
    });
    

    给你的

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
    <script>
    $(document).ready(function()
    {
        $('div, p, img, span, a').bind("mousedown", function(e)
        {
            if (e.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;
    
    ?>
    

    【讨论】:

    • 如何在我发布的函数上实现它
    • 因为这项工作很奇怪我如何改变背景:悬停以知道隐藏了什么元素
    • @thescientist - 我投了你的票,我建议我的答案作为使用 1.7 + 解决他的问题的替代方案。
    • @user1094631 - 不确定我理解你的意思becouse this work very strange how I can change background on :hover to know what element is hide
    • 右键单击弹出窗口(这是一个 DIV)必须隐藏弹出窗口,但似乎不起作用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-17
    • 2015-02-27
    • 1970-01-01
    • 2010-11-08
    • 1970-01-01
    相关资源
    最近更新 更多