-1
var url = window.location.pathname;
var filename = url.substring(url.lastIndexOf('/')+1);
$("ul").find("a[href=filename]").addClass('active');
在我的header.php的UL:如何在php中使用特定的href将类添加到<a>?
<li><a href="index.php">Főoldal</a></li>
<li><a href="gallery.php">Galéria</a></li>
<li><a href="games.php">Játékok</a></li>
<li><a href="contacts.php">Elérhetőségeink</a></li>
<li><a href= "about.php">Rólunk</a></li>
我花了几个小时与此有关。根据我目前所在的网站,我无法将一个类添加到锚标记中。
让我们知道了什么是的console.log的'输出(文件名);'变种文件名= url.substring后'PH_1PH_1广告它(url.lastIndexOf( '/')+ 1);'和检查你的浏览器控制台,并让我们知道 –
做'$(“ul> li> a [href ='”+ filename +“'”)“)。addClass('active')'可能会起作用,尽管最好添加类因为PHP知道哪一部分更准确(例如,如果你打算使用重写等) – apokryfos