单击每个链接时,我想将当前状态设置为选中。我可以通过以下方式做到这一点:
HTML
<ul class="places">
<li class="selected">
<a href="javascript:void(0)" onclick="myClick(0);">
<span class="date">Saturday November 2, 2013</span>
<span class="time">10am – 12pm</span>
<span class="location">Western Sydney Parklands</span>
</a>
</li>
<li>
<a href="javascript:void(0)" onclick="myClick(1);">
<span class="date">Saturday November 9, 2013</span>
<span class="time">10am – 12pm</span>
<span class="location">Bankstown High School</span>
</a>
</li>
<li>
<a href="javascript:void(0)" onclick="myClick(2);">
<span class="date">Tuesday November 12, 2013</span>
<span class="time">9am – 11am</span>
<span class="location">Greystanes Park</span>
</a>
</li>
</ul>
查询
$(document).ready( function() {
$('.places li a').click( function() {
$('.places li').removeClass('selected');
$(this).parent().addClass('selected');
});
});
但这会在每个链接上双重触发 onclick 事件,因为调用函数myClick()
将数据推送到地图。然后我决定在myClick()
函数中实现这些:
function myClick( id ) {
google.maps.event.trigger(markers[id], 'click');
$('.places li').removeClass('selected');
$(this).parent().addClass('selected');
}
问题是我不能使用$(this)
将类添加到其父级li
。看看我在这里尝试了什么。
任何帮助将不胜感激。谢谢!