jquery,触发链接点击与另一个点击问题?
我有这种情况。我正在使用此处的简单选项卡菜单。
<ul class="tabs">
<li><a href="#tab1">tab1</a></li>
<li><a id="myprofile" href="#tab2">tab2</a></li>
</ul>
<div id="tab1" class="tab_content">
text
</div>
<div id="tab2" class="tab_content">
text
</div>
到目前为止,一切都很好。
我想要做的是从另一个链接触发 #myprofile
:
<a id="my_profile" href="" title="My Profile">My Profile</a>
我正在尝试使用类似这样的东西:
$('#my_profile').click(function() {
// $('#myprofile').click(); // this works
$('#myprofile').trigger('click'); // this works also
});
当我单击新链接 #my_profile
时会发生什么,我进入第二个选项卡大约 2 秒,然后我被重定向到第一个选项卡。但如果我点击选项卡,它就可以正常工作。
如果我使用 jsfiddle,我会收到 {"error": "Please use POST request"}
错误:请参阅 这里,但不在我的页面上。
有什么想法吗?
谢谢
i have this situation. I am using a simple tab menu from here.
<ul class="tabs">
<li><a href="#tab1">tab1</a></li>
<li><a id="myprofile" href="#tab2">tab2</a></li>
</ul>
<div id="tab1" class="tab_content">
text
</div>
<div id="tab2" class="tab_content">
text
</div>
so far so good.
What i want to do is to trigger #myprofile
from another link:
<a id="my_profile" href="" title="My Profile">My Profile</a>
I am trying to use something like this:
$('#my_profile').click(function() {
// $('#myprofile').click(); // this works
$('#myprofile').trigger('click'); // this works also
});
What happens is that when i click on the new link #my_profile
, i go to the second tab for like 2 seconds then i get redirected to the first tab. But if i click on the tabs it works just fine.
if i use jsfiddle i get a {"error": "Please use POST request"}
error: see here, but not on my page.
any ideas?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一次
try this once
如果您使用 jquery 选项卡。试试这个,
请参阅这个。
If you are using jquery tabs. Just try this,
See this.