gpt4 book ai didi

javascript - 将类添加到 HTML 元素

转载 作者:行者123 更新时间:2023-11-28 19:54:24 25 4
gpt4 key购买 nike

我想将类添加到 <li>元素为 <a href="http://localhost/hello/5">元素。

我尝试了,但没用:

$("<li><a>[href|='http://localhost/hello/5']").addClass( "active" );

最佳答案

添加到父项 <li> :

$("[href='http://localhost/hello/5']").parent("li").addClass( "active" );

关于javascript - 将类添加到 HTML 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22846505/

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