我有一點點javascript可以在頁面上找到鏈接,如果它與當前頁面的鏈接相同,它會將css更改爲當前鏈接。這工作正常。但是我想要做的就是擴展這個,例如讓相同的鏈接是mysite.com/blog/post。我希望它去了一個目錄,即mysite.com/blog找到,如果鏈接頁面上,如果它是突出它,希望這使得sense.The代碼我是:從當前鏈接中查找鏈接路徑目錄(javascript)
<script type="text/javascript">
$(document).ready(function() {
var path = location.pathname;
if (path)
$('#sidebar ul.archive a[href$="' + path + '"]').attr('class', 'current');
});
</script>
所以我以爲我只需要改變var路徑來找到上面的目錄的鏈接,但不知道我該怎麼做呢?
如果path是'/ a/b/c /',那麼'/ a/b/c /../'是父目錄。它不漂亮,但它是有效的。 – 2012-01-31 16:54:07