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

发布于 2024-12-06 04:32:14 字数 1457 浏览 1 评论 0原文

我有一个包含 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)添加一个类。

I have a page of more than 2500 anchor tag to process. Now in IE it is throwing the stop script error. Is it possible to do as a batch? Taking 500 executing it and then take the another 500 executing it??

This is the code...

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){}

Iam adding a class for all the anchor tag(which is 2500) in a page.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

话少心凉 2024-12-13 04:32:14

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);
    }
}

上面的代码未经测试,但应该可以工作。

jQuery's .slice may help you.
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);
    }
}

The above code is not tested, but should probably work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文