Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript阻止单击_Javascript_Html - Fatal编程技术网

javascript阻止单击

javascript阻止单击,javascript,html,Javascript,Html,我用这段代码来滑动一些信息 JavaScript $(function() { $('#bottom_menu li a').click(function(e) { e.preventDefault(); animateSlider(this.hash); }); function animateSlider(hash) { if (!$('#container div.open').length) {

我用这段代码来滑动一些信息

JavaScript

$(function() {
    $('#bottom_menu li a').click(function(e) {
        e.preventDefault();
        animateSlider(this.hash);
    });

    function animateSlider(hash) {
        if (!$('#container div.open').length) {
            if (hash == '#about') {
                openPopup(hash);
            }
            if (hash == '#contact') {
                openPopup(hash);
            }
        } else {
            if (hash == '#about') {
                openAndClose(hash)
            }
            if (hash == '#contact') {
                openAndClose(hash)
            }
        }
    }

    function openPopup(hash) {
        $(hash + '_popup').slideToggle().addClass('open');
    }

    function openAndClose(hash) {
        if ($(hash + '_popup').hasClass('open')) {
            $($(hash + '_popup')).slideToggle().removeClass();
        } else {
            $('#container div.open').slideToggle().removeClass();
            $(hash + '_popup').slideToggle().addClass('open');
        }
    }
});
HTML

<nav id="men55">
    <ul id="bottom_menu">
        <li style="text-align:left;">
            <a href="#about"><font face="din" size="4">onde <br />estamos</font></a>
        </li>
        <li style="text-align:left;">
            <a href="#contact"><font face="din" size="4">osnossos<br />parceiros</font></a>
        </li>
        <li style="text-align:left;">
            <a href="index2.php?web=news" <?php if($web == "news") {echo 'class="corrente"';} ?>><font face="din" size="4">news <br />press</font></a>
        </li>
    </ul>
</nav>


问题是,当href=#contact或href=#about工作正常时,但是如果我想把a href=index2.php?web=teste放进去,那么就不工作了。。。什么都没发生。。。问题是javascript阻止在nav或li中单击,只需更改初始选择器,仅选择其
href
属性以“#”开头的锚定标记,使用
[href^=“#”]
。更改:

$('#bottom_menu li a').click(function(e) { ... });
致:

这将忽略
href
属性不以“#”开头的任何链接:


因为您正在检查hash-
this.hash
。谢谢,但很抱歉,我不能像您所说的那样更改代码。。。你能更改我的原始代码并发送给我吗?谢谢你again@Ricardo您在问题中发布的代码的第二行是
$(“#底部菜单li a”)
。只需将其更改为
$('#bottom_菜单li a[href^=“#“]”)
。为了更清楚,我编辑了我的答案。
$('#bottom_menu li a[href^="#"]').click(function(e) { ... });
#about /* Prevented */
#contact /* Prevented */
index2.php /* Ignored */
index2.php?web=teste /* Ignored */
index2.php#test /* Ignored */