[英]select li from ul : drop down box with Javascript and Jquery
I have this html from a webpage: 我有一个网页中的html:
<div class="form-group">
<div class="btn-group">
<button type="button" id="tgbtn"
class="btn btn-default" style="min-width: 110px;">Search by</button>
<button type="button" data-toggle="dropdown"
class="btn btn-default dropdown-toggle">
<span class="caret"></span>
</button>
<ul class="dropdown-menu pull-left">
<li><a href="#">Name</a></li>
<li><a href="#">Parcel #</a></li>
<li><a href="#">PIN</a></li>
<li><a href="#">Property Location</a></li>
<li><a href="#">Mailing Address</a></li>
</ul>
The above code forms a drop down box on the web page, through one of the JS libraries , but of-course it not a select -option
dropdown box. 上面的代码通过一个JS库在网页上形成了一个下拉框,但是,当然,它不是一个select
-option
下拉框。 What I need in this particular case is one line of javascript preferably (2nd: jquery) that will set the 'Mailing Address'
to be selected in the pseudo-drop down. 在这种特殊情况下,我需要的是一行JavaScript(最好是第二行:jquery),它将在伪下拉列表中选择要选择的
'Mailing Address'
。
I have tried a few things with no success. 我尝试了几件事没有成功。 This is for web scraping of another website, which is why I'm looking for a one liner, not a function, etc.
这是用于另一个网站的网页抓取,这就是为什么我要寻找一个衬板而不是功能等的原因。
You can use eq. 您可以使用eq。 Reduce the set of matched elements to the one at the specified index.
将匹配的元素集减少到指定索引处的元素。
Jquery: jQuery的:
$('.form-group').find('.dropdown-menu').find('li').eq(4).click();
You can provide the index of the element you want to select to the .eq(index)
method. 您可以将要选择的元素的索引提供给
.eq(index)
方法。
$('.form-group').find('.dropdown-menu').find('li').last().click();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.