这是我的 html 菜单按钮:
<tr>
<td><a href="http://exmple.com/2014/09/28.html">23</a></td>
<td><a href="http://exmple.com/2014/09/24.html">24</a></td>
<td><a href="http://exmple.com/2014/09/25.html">25</a></td>
</tr>
如何在当前 URL 上添加这个类?
<td class="active"><a href="http://example.com/2014/09/25.html">25</a></td>
我怎样才能完成这项工作?
最佳答案
$('table td a').click(function(e){
$('table td').removeClass('active');
$(this).parent('td').addClass('active');
e.preventDefault();
});
.active a{
color: #f00;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<table>
<tr>
<td><a href="http://exmple.com/2014/09/28.html">23</a></td>
<td><a href="http://exmple.com/2014/09/24.html">24</a></td>
<td><a href="http://exmple.com/2014/09/25.html">25</a></td>
</tr>
</table>
这是解决方案。根据您的需要使用它。
关于html - Blogger 事件链接类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26056044/