gpt4 book ai didi

jQuery href 左键单击不起作用

转载 作者:行者123 更新时间:2023-11-27 22:42:32 25 4
gpt4 key购买 nike

得到了我从一本书(新手到忍者)中稍微改编的代码。

用户点击“联系人”,下方会打开一个表单,其中包含电话号码和 href 链接。左键单击链接没有任何作用,但我可以右键单击并“在新选项卡中打开”,然后它就起作用了。

对 js 和 jQuery 相当陌生,但我认为问题(我可能错了)是无法正常工作的 href 链接与打开表单的“联系人”链接链接相同的“a”,但我不知道如何改变它。

      <div id="contact">
<a href="#">Contact</a>
<form action="">
Phone me on:018<br><br>Email me at <a href="http://www.guardian.co.uk/lifeandstyle/2012/apr/04/samantha-brick-hated-good-looks?newsfeed=true">click me</a>
</form>
</div>

查询

  $('#contact form').hide();
$('#contact a').toggle(function() {
$(this)
.addClass('active')
.next('form')
.animate({'height':'show'}, {
duration:'slow',
easing: 'swing'
});
}, function() {
$(this)
.removeClass('active')
.next('form')
.slideUp();
});

非常感谢

最佳答案

代替

$('#contact a')

尝试使用

$('#contact > a')

通过这种方式,您只针对直接子代而不是其他 <a> .我认为当您单击带有 href <a href="http://www.guardian.co.uk/lifeandstyle/2012/apr/04/samantha-brick-hated-good-looks?newsfeed=true">click me</a> 的链接时,您的代码片段也会运行, 并且脚本中断并且由于这个原因没有遵循链接

关于jQuery href 左键单击不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10028514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com