简体   繁体   English

Jquery 点击<li>下拉选项</li>

[英]Jquery Click <li> dropdown option

This is my code from WHMCS Client Area Dashboard.这是我来自 WHMCS 客户区仪表板的代码。

<ul class="dropdown-menu" role="menu">
    <li><a href="#"><span data-value="all">All Entries</span></a></li>
    <li><a href="#"><span data-value="Terminated">Terminated</span></a></li>
    <li><a href="#"><span data-value="Cancelled">Cancelled</span></a></li>
    <li><a href="#"><span data-value="Active">Active</span></a></li>
</ul>

I want to click "Active" option by default.我想默认单击“活动”选项。

After several tries, I figured out below code can work for me经过几次尝试,我发现下面的代码可以为我工作

$('.dropdown-menu li:nth-child(4) a').click();

But the issue is, Active tab is not fixed at 4th position.但问题是,活动选项卡未固定在第 4 个 position。

Want to change the below code so it actually use "Active" value instead of 4th option.想要更改下面的代码,使其实际使用“Active”值而不是第 4 个选项。

$('.dropdown-menu li:nth-child(4) a').click();

I am learning Jquery, already tried searching many threads.我正在学习 Jquery,已经尝试搜索很多线程。 Couldn't find one.找不到一个。 Need help.需要帮忙。

You can use data attribute for selector $('.dropdown-menu span[data-value="Active"]') .您可以使用选择器的数据属性$('.dropdown-menu span[data-value="Active"]')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM