我尝试在数据加载后运行js代码 它反过来工作现在首先它运行代码,在加载数据之前,删除类.active,我需要在点击另一个链接后删除类
这是我的代码:
$('document').ready(function() {
$('.links a').click(function(e) {
e.preventDefault();
$('.links a').not(this).removeClass('active');
$(this).addClass('active');
});
});
function Animate2id(id) {
// your function stuff
}
和我的HTML:
<div class ="links">
<a id="section-<?=$arParams['CODE']?>-link" href="#" onclick="ajax_load('#no-scroll-items-<?=$arParams['CODE'];?>', '<?=$arResult['AJAX_CALL_ID']?>', 'do=select_section&id=<?=4610?>'); return false;" class="" title="Мобильные телефоны">Мобильные телефоны</a>
<a id="section-<?=$arParams['CODE']?>-link" href="#" onclick="ajax_load('#no-scroll-items-<?=$arParams['CODE'];?>', '<?=$arResult['AJAX_CALL_ID']?>', 'do=select_section&id=<?=4611?>'); return false;" class="" title="Планшеты">Планшеты</a>
<a id="section-<?=$arParams['CODE']?>-link" href="#" onclick="ajax_load('#no-scroll-items-<?=$arParams['CODE'];?>', '<?=$arResult['AJAX_CALL_ID']?>', 'do=select_section&id=<?=4616?>'); return false;" class="" title="Монопады">Монопады</a>
<a id="section-<?=$arParams['CODE']?>-link" href="#" onclick="ajax_load('#no-scroll-items-<?=$arParams['CODE'];?>', '<?=$arResult['AJAX_CALL_ID']?>', 'do=select_section&id=<?=4630?>'); return false;" class="" title="Наушники">Наушники</a>
<a id="section-<?=$arParams['CODE']?>-link" href="#" onclick="ajax_load('#no-scroll-items-<?=$arParams['CODE'];?>', '<?=$arResult['AJAX_CALL_ID']?>', 'do=select_section&id=<?=4739?>'); return false;" class="" title="Медиаплееры">Медиаплееры</a>
<a id="section-<?=$arParams['CODE']?>-link" href="#" onclick="ajax_load('#no-scroll-items-<?=$arParams['CODE'];?>', '<?=$arResult['AJAX_CALL_ID']?>', 'do=select_section&id=<?=4593?>'); return false;" class="" title="Аксессуары">Аксессуары</a>
</div>
我错过了什么?
最好的问候
答案 0 :(得分:0)
试试这个:
$('document').ready(function() {
$('.links a').on('click', function(){
$('.links a').removeClass('active');
$(this).addClass('active');
});
});
现场演示:codepen
答案 1 :(得分:0)
$(document).ready(function() {
// executes when HTML-Document is loaded and DOM is ready
alert("document is ready");
});
$(window).load(function() {
// executes when complete page is fully loaded, including all frames, objects and images
alert("window is loaded");
});
否则使用settimeout
setTimeout(function(){ alert("call after 3000 mili sec"); }, 3000);