如何避免在浏览器中停止脚本错误

时间:2011-09-24 07:14:32

标签: javascript jquery-selectors internet-explorer-7

我有一个超过2500个锚标记的页面要处理。现在在IE中它抛出了停止脚本错误。是否可以批量生产?拿500执行它然后再拿500执行它??

这是代码......

ajaxLinks : function(el, flag) {
    var links = $(el).find('a');
    var notLinkAr=["a[href^=javascript]","#toolbarId ul li>a","#tool_settings .link a",".page-action-links li>a","#tool_settings .label a",".success-map .success-tabs li>a",".success-map .sm_loggedin li>a", ".analyst_cat li>a",".modal",".layer",".newpage",".close",".hideFromPopup",".pagenum",".next",".prev",".delete_src",".tips","#hidr","#backr"];
    $(notLinkAr).each(function(index){
        var notLinkI=$(notLinkAr[index]);
        if($(notLinkI).is("a")){
            if($(notLinkI).length>0){
                $(notLinkI).each(function(index1){
                        $(notLinkI[index1]).addClass("dontAjaxify");
                });
            }
        }
    });
     $(links).each(function(i, obj){
        var link = $(obj);
        if(!$(obj).hasClass('dontAjaxify')){
           link.attr('rel', link.attr('href'));
            var rellnk = link.attr('rel');
            if(flag=='ajaxified') {
                if(/http/.test(rellnk)){
                    var relurl;
                    relurl=rellnk.replace((window.location.protocol + "//"+ window.location.hostname),'')
                    link.attr('rel', relurl);;
                }
            }
            link.bind('click', function(e){}

我在页面中为所有锚标记(2500)添加了一个类。

1 个答案:

答案 0 :(得分:1)

jQuery的.slice可以帮到你。 http://api.jquery.com/slice/

var count = 0;
var ajaxify = function (el, flags) {
    var links = $(el).find('a').slice(count, count + 500);
    count = count + 500;

    // Do the processing here

    if (links.length) {
       // Call it next time only if some data is returned in the current call
       setTimeout("ajaxify()", 5000);
    }
}

以上代码未经过测试,但应该可以使用。

相关问题