Это мой код jQuery, когда он читает window.location.hash, он добавляет класс CSS к элементу, и он отображается. Но я не могу этого сделать, чтобы не дойти до этого якоря. Я попробовал preventDefault(), но, похоже, не работает.Предотвращение перехода на привязку с помощью jQuery
<script type="text/javascript">
function cotizar(n){
gotoSlide(n);
$('#cotizadores > div').removeClass();
$('#cotizadores > div').eq(n).addClass("cotizador_activo");
}
$(document).ready(function() {
if(window.location.hash != ''){
var hash = window.location.hash.substring(1);
index = $(".tab-content > div ").children("#boton_"+hash).index();
cotizar(index);
clearInterval(slideival);
}
$(".slides > div > a").on('click',function(event){
window.location.hash = $(this).parent().attr('id');
index = $(this).parent().index();
cotizar(index);
event.preventDefault();
return false;
});
});
</script>
This is my site url, попробуйте нажать 'ABRIR COTIZADOR' в любой из слайдов.
Спасибо!
Попробуйте поместить 'функцию cotizar' внутри документа готового –
возможного дубликата [Как я могу обновить window.location.hash без прыжков документа?] (Http://stackoverflow.com/questions/ 3870057/как-кан-я-обновление окна-местоположение-хэш-без прыжков-зе-документ) –