IE 8提示用户“慢” jQuery脚本 [英] IE 8 prompts user on "slow" jQuery script

查看:114
本文介绍了IE 8提示用户“慢” jQuery脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,超过100个列表项,我必须重新排序提交。以下代码用于在Firefox中重新排序列表,没有任何明显的问题;然而,IE提示输入消息此页面上的脚本导致Internet Explorer运行缓慢,如果继续运行,您的计算机可能会无响应,您要中止脚本吗?如果用户点击否,脚本将按预期工作。

I have a form with over 100 list items that I must reorder on submit. The following code works to reorder my list without any apparent problems in Firefox; however, IE prompts with the message "A script on this page is causing Internet Explorer to run slowly. If it continues to run, your computer may become unresponsive. Do you want to abort the script?" If the user clicks 'No', the script will work as expected.

var listitems = $(form).find('li').get();
listitems.sort(function(a, b) {
    var compA = $(a).attr('id');
    var compB = $(b).attr('id');
    return (compA - compB);
});

任何有关如何提高效率的想法?

Any ideas on how to make this more efficient?

推荐答案

我没有尝试100项,但它完全与2。

I didn't try it with 100 items but it totally worked with 2.

listitems.sort(function(a, b) {
    return (a.id - b.id);
});

这篇关于IE 8提示用户“慢” jQuery脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆