首页javascriptanchorjQuery HTML Element - 如何添加选定锚点的样式

jQuery HTML Element - 如何添加选定锚点的样式

我们想知道如何添加选定锚点的样式。

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.5.2.js'></script>
<style type='text/css'>
a.selected {
  background-color: #ddf;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    $('a').click(function() {
        $('.selected').removeClass('selected');
        $(this).addClass('selected');
    });
});
</script>
</head>
<body>
  <a href="#">Link 1</a>
  <a href="#">Link 2</a>
</body>
</html>