【问题标题】:jQuery stopping url click in div attached to functionjQuery在附加到函数的div中停止url点击
【发布时间】:2015-02-04 16:27:35
【问题描述】:

我有一个像这样设置的 div

<div class="clickformore">
  <h3>Business in<br>action</h3>
  <div class="foundoutmore">
    <div class="uparrow"></div>
    <div class="underarrow">
      <p>Develop critical and problem solving skills faculties by investigating challenges faced by business leaders and to practice the skills to devise and implement practical solutions.<br><a href="http://www.ncl.ac.uk/postgraduate/modules/module/NBS8490/" target="_blank">http://www.ncl.ac.uk/postgraduate/modules/module/NBS8490/</a></p>
    </div>
  </div>
</div>

只有 h3 是可见的,其他的都是隐藏的。 jQuery 显示找到的更多 div,其中包含箭头和文本框,使其看起来像一个气泡。

但是当用户点击隐藏的 div 中的链接时,它会再次隐藏,而不是打开链接。

$(".clickformore").click(function(e){
    e.preventDefault();
    if ($(this).find(".foundoutmore").css('display') == 'none') {
        $(".foundoutmore").css("display","none");
        $(this).find(".foundoutmore").css("display","inherit");
    } else {
        $(".foundoutmore").css("display","none");
    }
});

我已经尝试用 css 做一个 z-index 来瞄准链接,希望它在 div 隐藏无济于事之前首先是可点击的,我试图找出一种方法让显示的 div 不再隐藏它,但我无法弄清楚系绳的结束。

有没有办法在 div 隐藏之前使链接可点击?

【问题讨论】:

    标签: jquery html show-hide


    【解决方案1】:

    使用这个兄弟..

    $(".foundoutmore").css("display","none");
    $("h3").click(function(e){
        e.preventDefault();
    
        if($(this).next().css('display')=='none'){
            $(this).next().css("display","inherit");
        } else {
            $(".foundoutmore").css("display","none");
        }
    });
    

    DEMO

    【讨论】:

    • 这行得通,谢谢。我添加到这个是因为我有不止一次点击,我需要点击一个新的来隐藏所有其余的而不是让它们保持打开状态。 $("h3").click(function(e){ e.preventDefault(); if($(this).next().css('display')=='none'){ $(".foundoutmore").css("display","none"); $(this).next().css("display","inherit"); } else { $(".foundoutmore").css("display","none"); } });(显然我不知道这个造型的东西在这个网站上是如何工作的,去看看)
    【解决方案2】:
    <div class="clickformore">
    
        <h3>Business in<br>action</h3>
    
        <div class="foundoutmore hidden">
            <div class="uparrow"></div>
            <div class="underarrow">
                <p>Develop critical and problem solving skills faculties by investigating challenges faced by business leaders and to practice the skills to devise and implement practical solutions.
                    <br><a href="http://www.ncl.ac.uk/postgraduate/modules/module/NBS8490/" target="_blank">http://www.ncl.ac.uk/postgraduate/modules/module/NBS8490/</a>
                </p>
            </div>
        </div>
    </div>
    
    
    
    
    $(".foundoutmore").hide();
    

    或添加

    .hidden {
      display: none;
    }
    

    然后到你的 CSS:

    $(".clickformore").on('click', 'h3', function(e){
        e.preventDefault();
        var more = $(this).next('.foundoutmore');
        more.toggle();
    });
    

    Demo

    【讨论】:

    • 我不完全确定为什么,但这在我的代码中不起作用。我猜它一定与已经存在的代码冲突。还是谢谢!
    猜你喜欢
    • 2015-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多