简体   繁体   English

点击按钮后链接无效

[英]link doesn't work after click button

I use a switch of content button inside div "integel1". 我在div“ integel1”中使用了内容按钮的开关。 The contact link (javascript) id="link" class="link2", works but not after i clicked on Button"knop3". 联系人链接(javascript)id =“ link” class =“ link2”,有效,但在我单击按钮“ knop3”后无法使用。 It needs to scroll down or up but AFTER that i click on the button the it just doesn't work. 它需要向下或向上滚动,但是在我单击按钮之后,它根本不起作用。 Does someone know why this is? 有人知道这是为什么吗?

 //This is the function when clicking the link: $(function() { "use strict"; $('.link2').on('click', function() { $('html,body').animate({ scrollTop: $(".footer").offset().top * 0.976 }, 850); }); }); //And this is the code for switching between different content: $('#knop3').on('click', function() { if ($('#5').css('display') != 'none') { $('#6').html($('#static2').html()).show().siblings('div').hide(); } else if ($('#6').css('display') != 'none') { $('#5').show().siblings('div').hide(); } }); $('#knop3').click(function() { var $this = $(this); $this.toggleClass('SeeMore2'); if ($this.hasClass('SeeMore2')) { $this.text('Minder info!'); } else { $this.text('Meer info!'); } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="integel1"> <button id="knop3">Meer info!</button> <div id="5" style="border: none; outline: none;"> <p id="titelchange" style="text-align: center;">CMS Website</p> <p class="prijsinfo"> &#10004; &emsp;Uniek ontwerp responsive. </p> <p class="prijsinfo"> &#10004; &emsp;Inclusief (wordpress) CMS. </p> <p class="prijsinfo"> &#10004; &emsp;Te bereiken voor alle vragen <a id="link" class="link2" href="javascript:;">contact</a>.</p> <p class="prijsinfo"> &#10004; &emsp;Vele plugin's kunnen geïnstalleerd worden.</p> <p style="margin-top:5vmax;" class="prijs"> *Prijs vanaf 179,99 euro,-</p> </div> <div id="6" style="display: none; outline: none; border: none;"></div> <div id="static2" style="display: none;"> <p class="prijsinfo">Een <b>CMS website</b> staat voor Content Management System: u kunt zelf makkelijk vanaf thuis de inhoud van uw website veranderen. Dit word ook gemaakt met een unieke vormgeving en helemaal responsive voor mobiel en tablet. Het is door het systeem makkelijk om pagina's aan te maken, maar ook tekst, foto's en filmpjes. Het is daarom handig om voor dit pakket te kiezen als u zelf veel inhoud wilt aanpassen.<br> <br> Wees niet gevreesd over de complexiteit, het werkt ongeveer alsof u in een tekstverwerker werkt. Het is heel eenvoudig en als u vragen heeft kunt u altijd <a id="link" class="link2" href="javascript:;">contact</a> met ons opnemen. <br> <br> </p> <p class="prijs">*Prijs CMS website vanaf 179,99 euro,-</p> </div> </div> <div class='footer'></div> 

Help is appreciated 感谢帮助

It's not working because, well, you're missing the footer. 它不起作用,因为,很可能您缺少页脚。

 ...

</div>
</div>
<div class='footer'></div>

And you're missing an html element with class link2 . 而且您缺少带有link2类的html元素。 Not sure if you meant to use the id, or to put the class on the button. 不知道您是要使用id还是将类放在按钮上。 But I made a jsfiddle for you with a working example. 但是我通过一个可行的例子为您制作了一个jsfiddle

<button class="link2" id="knop3">Meer info!</button>

Just put this at the end, or where you want your footer. 只需将其放置在末尾或您想要的页脚位置即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM