Can';t使用click trigger jQuery执行代码
我有一个用于选项卡的jQuery代码,它在单击选项卡并使用AJAX函数加载内容时运行良好,这是HTML代码中链接的外观:Can';t使用click trigger jQuery执行代码,jquery,Jquery,我有一个用于选项卡的jQuery代码,它在单击选项卡并使用AJAX函数加载内容时运行良好,这是HTML代码中链接的外观: <ul class="tabset"> <li class="category-all"> <a id="latest-news.all" href="http://www.website.com/#latest-news.all">All</a> </li> <li class="category-
<ul class="tabset">
<li class="category-all">
<a id="latest-news.all" href="http://www.website.com/#latest-news.all">All</a>
</li>
<li class="category-games">
<a id="latest-news.games" href="http://www.website.com/#latest-news.games">Games</a>
</li>
<li class="category-other">
<a id="latest-news.other" href="http://www.website.com/#latest-news.other">Other</a>
</li>
</ul>
加载页面时,我尝试使用URL哈希以以下方式打开特定选项卡:
if (window.location.hash) {
$(window.location.hash).click();
}
但它不起作用,我已经尝试了.trigger('click')版本,但它也不起作用
非常感谢您的帮助。为确保您的帮助不会过时,请尝试
setTimeout(function{
$(hash).click():
},5000);
document.ready(function(){
$(hash).click():
}
确保has是锚的id,例如://
#firstdiv
可能您只是缺少阻止在
回调中执行默认的单击处理程序。在('click')
回调中:
e.preventDefault();
e.preventDefault();