2017-05-30 114 views
-1

如果我想使用这个链接http://localhost:8086/IAPApp/lead/index.html所以我应该怎么写的函数jQuery中,这样与/铅会得到displayed.That开始的所有页面单元,其中包含的任何链接/铅网址应该displayed.I写的功能jQuery选择的HREF链接

<script type="text/javascript"> 
$(document).ready(function(){ 
$('a[href^="IAPApp/lead/"]') 
}); 

<a href="data-index.html" style="visibility: hidden"></a> 
<a href="data-riskAssessment.html" style="visibility: hidden"></a> 
+3

上面的HTML/JS示例与您的问题描述完全无关。无论哪种方式,使用'属性包含'选择器,而不是'当前属性开始于'选择器',例如'$('a [href * =“/ lead”]');' –

+0

无论何时领先链接是可变的,那么我给出的其他两个链接必须隐藏起来。这就是为什么我写了可见性:隐藏 – Aishwarya

回答

1

我会用包含[attribute*="value"]选择。您可以查看所有可用的选择here

HTML:

<a href="http://localhost:8086/IAPApp/notlead/index.html">hidden</a> 
<a href="http://localhost:8086/IAPApp/lead/index.html">visible</a> 

JS:

$(document).ready(function(){ 
    $('a').hide(); // Hides all Anchors 
    $('a[href*="/lead/"]').show(); // Display only this ones who contains the "/lead/" 
}); 

JsFIDDLE

+0

这将只与主页一起工作,但是如果我想与其他链接一起使用,那么我的意思是如果我包含将启动的各种链接与/ abc /同样 – Aishwarya

+0

我还必须隐藏其他链接。如何有可能? – Aishwarya

+0

隐藏您可以在示例中查看的其他链接。你是什​​么意思与其他链接?你有一些例子链接? –