gpt4 book ai didi

jquery - 如何查找 Jquery 是否在某处禁用 html 中的 anchor 标记

转载 作者:行者123 更新时间:2023-11-28 08:32:14 24 4
gpt4 key购买 nike

我确实有一些代码在 li 元素中包含 anchor 标记,当我单击时,我仍然在同一页面上,当我右键单击并在新选项卡中打开链接时,它工作正常。如果我在网页的任何 Angular 落替换 anchor 标记,它可以工作,但在 div 中不起作用对于相同的尝试设置 z-index 但没有用,是否有任何解决方案。这是代码..

<div class="side-banner" style="width:288px; float:left;height:auto; z-index:1001;">
<div id="menu" style="float:left; width:auto;height:auto;">
<nav id="nav" style="width:auto; height:auto;z-index:1000">
<h2><i class="fa fa-reorder"></i>All Categories</h2>
<ul>
<li>
//This Link doesn't works
<a href="@Url.Action("Create")"><i class="fa fa-laptop"></i>Organizer</a>
<h2><i class="fa fa-laptop"></i>Organizer</h2>
</li>
<li>
//This doesn't works
<a href="/Home/Index"><i class="fa fa-book"></i>Project Info</a>
<h2><i class="fa fa-book"></i>Project Info</h2>
</li>
<li>
<a href="#"><i class="fa fa-shopping-cart"></i>Human Resource</a>
<h2><i class="fa fa-shopping-cart"></i>Human Resource</h2>

</li>
<li>
<a href="#">Collections</a>
</li>
<li>
<a href="#">Credits</a>
//Now this link works fine
@Html.ActionLink("Create","Create")
</li>
</ul>
</nav>
</div>
</div>
<div>
@RenderBody()
</div>

感谢阅读

最佳答案

您可以使用 isDefaultPrevented() 来检查链接默认操作是否已被 jquery 阻止。

所以如果你在某个地方有类似的东西:

$('a.someLink').click(function (evt) {
evt.preventDefault(); // stops the link working
});

这会阻止链接正常工作(链接到 url)

isDefaultPrevented() returns true/false if an event has been stopped. i.e.

$('a').click(function (e) {
e.preventDefault();
e.isDefaultPrevented(); // returns true
});

您需要查看潜在禁用链接的内容/方式/时间,然后绑定(bind)到一些 a 标签并检查这些事件是否已停止(如果您发布您的 javascript,我们可能会进一步建议)

这是一个演示,说明如何检查其他地方的链接是否已阻止默认设置

<a id='myLink' href='http://facebook.com'>link</a>


$(function (){
// lets say you've bound events some where
$('#myLink').click(function (e){
e.preventDefault();
});


// somewhere else in the code you can bind to all `a` tags and test
// if the default has been prevented

$('a').click(function (e) {
alert(e.isDefaultPrevented());
});
});

关于jquery - 如何查找 Jquery 是否在某处禁用 html 中的 anchor 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28214358/

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