Я использую эту функцию для динамической загрузки страниц на моем сайте, и она отлично работает для меня, за исключением одной маленькой проблемы, которая есть Итерация по всем якорным тегам a
на моем но я хочу, чтобы он повторял только мое навигационное меню! это все. вот мое меню для наивного.Как ограничить функцию только одним элементом DOM по id или классу
<div id="vertical-menu">
<nav>
<ul id='menu' class="menu-items">
<li><a href="#Browse/Browse_Page1.php"><i class="arcd-archive"></i></br>Browse</a></li>
<li><a href="#Top_albums/Top_albums_Page0.php"><i class="arcd-music97"></i></br>Top albums</a></li>
<li><a href="#Top_artists/Top_artists_Page0.php" ><i class="arcd-microphone52"></i></br>Top artists</a></li>
<li><a href="#Top_lists/Top_lists_Page0.php" ><i class="arcd-numbered8"></i></br>Top lists</a></li>
<li><a href="#Charts/Charts_Page0.php" ><i class="arcd-rising9"></i></br>Charts</a></li>
</ul>
</nav>
</div>
и это функция, о которой я говорю.
$(function(){
// Keep a mapping of url-to-container for caching purposes.
var cache = {
// If url is '' (no fragment), display this div's content.
'': $('#default-homepage-contents').fadeIn('fast'),
};
// Bind an event to window.onhashchange that, when the history state changes,
// gets the url from the hash and displays either our cached content or fetches
// new content to be displayed.
$(window).bind('hashchange', function(e) {
// Get the hash (fragment) as a string, with any leading # removed. Note that
// in jQuery 1.4, you should use e.fragment instead of $.param.fragment().
var url = $.param.fragment();
// Remove .bbq-current class from any previously "current" link(s).
$('a.bbq-current').removeClass('bbq-current');
// Hide any visible ajax content.
$('#main-container').children(':visible').hide();
// Add .bbq-current class to "current" nav link(s), only if url isn't empty.
url && $('a[href="#' + url + '"]').addClass('bbq-current');
if (cache[ url ]) {
// Since the element is already in the cache, it doesn't need to be
// created, so instead of creating it again, let's just show it!
cache[ url ].fadeIn(1000);
} else {
// Show "loading" content while AJAX content loads.
$('#loading').show();
// Create container for this url's content and store a reference to it in
// the cache.
cache[ url ] = $('<div class="bbq-item"/>')
// Append the content container to the parent container.
.appendTo('#main-container')
// Load external content via AJAX. Note that in order to keep this
// example streamlined, only the content in .infobox is shown. You'll
// want to change this based on your needs.
.load(url, function(){
// Content loaded, hide "loading" content.
$('#loading').fadeOut(1000);
});
}
})
// Since the event is only triggered when the hash changes, we need to trigger
// the event now, to handle the hash the page may have loaded with.
$(window).trigger('hashchange');
});
</script>
, как вы можете видеть на линии 18 и 25, он обращается к HTML элемент я пытался изменить его с помощью различных selecters как #nav a
и nav ul#menu a
, но ничего работы. Ваша помощь будет оценена по достоинству.
спасибо! меня устраивает. – arcade