我有一个基础下拉列表,如下所示
<a href="#" data-dropdown="drop1" id="dateTitle">Date Range </a>
<ul id="drop1" class="f-dropdown small date-menu" drop-down-content>
<li id="custom">Custom</li>
<div id="customContainer"></div>
<li id="today"> Today</li>
<li id="yesterday">Yesterday</li>
<li id="sundaytoToday">This Week(Sun-Today)</li>
<li id="montoToday">This Week(Mon-Today)</li>
<li id="lastSevenDays">Last 7 Days</li>
<li id="lastSuntoSat">Last Week(Sun - Sat)</li>
<li id="lastMontoSun">Last Week(Mon - Sun)</li>
<li id="lastBusinessWeek">Last Business Week(Mon - Fri)</li>
<li id="lastFourteenDays">Last 14 days</li>
<li id="thisMonth">This Month</li>
<li id="lastThirtyDays">Last 30 days</li>
<li id="lastMonth">Last Month</li>
<li id="allTime">All Time</li>
<hr>
<li id="compare">Compare
<div class="onoffswitch">
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch">
<label class="onoffswitch-label" for="myonoffswitch">
<div class="onoffswitch-inner"></div>
<div class="onoffswitch-switch"></div>
</label>
</div>
</li>
<div id="extraContainer"></div>
<div align="center"><button class="date-picker-submit">Apply</button></div>
</ul>
当用户点击列表项目然后点击底部的应用按钮时,我想抓住列表中的所选项目
我没有得到怎么做
$('.date-picker-submit').click(function(){
//get the selected value
});
答案 0 :(得分:1)
这样做:
$('#drop1 li').click(function(){
$('#drop1 li').removeClass("selected");
$(this).addClass("selected");
});
现在点击按钮:
$('.date-picker-submit').click(function(){
$('#drop1 li.selected').text();
});