删除ID属性,从我的网址链接 [英] Removing id attribute to link from my url

查看:101
本文介绍了删除ID属性,从我的网址链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,我不知道链接到我的网页部分的id属性在点击它后卡在url中。

< a href =#secondbutton class =btn>点击此处预订< / button>< / a>< a id =second>< / a> code>



要查看我的意思的实例,请访问[plushvip .com 1 ,点击第一个按钮查看我的意思。



任何想法?

解决方案

#1 它是如何工作的

#2 :正如在另一个被称为散列的回答中所指出的那样,您将使用jquery来修复它。我喜欢这个小脚本,它消除了散列,并且有一个很好的滚动动画而不是跳转:

JQuery:

  jQuery(document).ready(function($){
$(。scroll)。click(function(event){
event.preventDefault();
$ ('html,body')。animate({scrollTop:$(this.hash).offset()。top},1000);
});
});

HTML:

 < a href =#secondclass =scroll> 
< button class =btn>点击此处预订< / button>
< / a>

演示:

http://jsfiddle.net/ImagineStudios/c604vbrn/11/


For some reason unknown to me the id attribute to link to a section of my webpage gets stuck in the url after clicking on it.

<a href="#second" button class="btn">Click Here To Pre-Order</button></a>

<a id="second"></a>

To see a live example of what I mean you can please visit [plushvip.com1, click on the first button to see what I mean.

Any ideas?

解决方案

#1: That's how it is supposed to work
#2: As noted in the other answer that is called hashes, and you would use jquery to fix it. I like this little script it removes the hashes, and has a nice scroll animation instead of a jump:
JQuery:

jQuery(document).ready(function($) {
    $(".scroll").click(function(event) {
       event.preventDefault();
       $('html,body').animate( { scrollTop:$(this.hash).offset().top } , 1000);
    });
});

HTML:

<a href="#second" class="scroll" >
<button class="btn">Click Here To Pre-Order</button>
</a>

Demo:
http://jsfiddle.net/ImagineStudios/c604vbrn/11/

这篇关于删除ID属性,从我的网址链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆