将鼠标悬停在<a> tags

时间:2016-12-16 14:23:35

标签: javascript jquery

I would like to use the below code to hide the URLs when hovering over <a> tag links. Below it is set to a certain <a> tag (#no-link), I want it to apply to all <a> tags. Can anyone help please?

$(document).ready(function () {
  setTimeout(function () {
        $('a[href]#no-link').each(function () {
            var href = this.href;

            $(this).removeAttr('href').css('cursor', 'pointer').click(function () {
                if (href.toLowerCase().indexOf("#") >= 0) {

                } else {
                    window.open(href, '_blank');
                }
            });
        });
  }, 500);
});

2 个答案:

答案 0 :(得分:1)

这应该可行,现在您正在选择所有锚元素。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick.min.js"></script>

答案 1 :(得分:0)

我不确定这个答案,我只是试图隐藏锚标签

<script src="http://code.jquery.com/jquery-latest.min.js"
            type="text/javascript"></script>
    <a class="no-link" href="samp1.html">samp1</a>
    <a class="no-link" href="samp2.html">samp2</a>
    <script>
    $(document).ready(function () {
    $('.no-link').hover(function(){
    $(this).hide();
    })

    });
    </script>