【问题标题】:how to run jquery code, after data load数据加载后如何运行jquery代码
【发布时间】:2015-07-14 06:42:21
【问题描述】:

我尝试在数据加载后运行 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>

我错过了什么? 最好的问候

【问题讨论】:

标签: javascript jquery html css ajax


【解决方案1】:

试试这个:

$('document').ready(function() {
   $('.links a').on('click', function(){
      $('.links a').removeClass('active');
      $(this).addClass('active');
   });
});

现场演示:codepen

【讨论】:

  • 谢谢,但我也有同样的问题,加载数据后,它删除了 class .active
【解决方案2】:
$(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);

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2012-10-22
  • 1970-01-01
  • 2017-08-01
  • 1970-01-01
  • 2011-04-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多