需要一些帮助来构建此 JQUERY 条件的逻辑语法。
如果当前 url 窗口包含特定的$string
(index.php),那么我想向特定的<li>
类添加一个值。如下所示。
<ul class="nav">
<li>...</li>
<li>index</li>
</ul>
这是目标元素
('.nav li:nth-child(2) ').addClass("selected")
。
这是我的jQuery。我不太确定如何为我的逻辑编写正确的语法。
$j(function(){
var url = window.location.pathname;
var string = 'index.php';
if //current url has $string ('index.php') {
$j( ".nav li:nth-child(2)" ).addClass( "active" );
});
});