使用jquery Validate的长格式导致IE缓慢的脚本警告 [英] Long form using jquery Validate causes IE slow script warning

查看:111
本文介绍了使用jquery Validate的长格式导致IE缓慢的脚本警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用jquery验证插件 http://bassistance.de/jquery-插件/jquery-plugin-validation/.它已经成功地工作了,尽管现在我有一个带有表的表格,该表格有100左右行,每行都有一个输入框

I have been using jquery validate plugin http://bassistance.de/jquery-plugins/jquery-plugin-validation/. It has been working successfully, though now I have a form with a table, with 100 or so rows, each with an input box

http://jsfiddle.net/X8tsR/

这会导致IE中出现此页面上的脚本导致Internet Explorer运行缓慢"的警告.

This causes the "a script on this page is causing internet explorer to run slowly" warning in IE.

我想知道我的实现是否存在问题,或者期望此验证脚本在这么多的内容上运行是不合理的?

I am wondering if there is a problem with my implementation or if it is just unreasonable to expect this validation script to run on this much content?

推荐答案

页面是单线程的,因此运行时间较长的脚本将导致页面锁定.诸如Internet Explorer之类的浏览器在整个浏览器中使用一个线程,因此,整个浏览器将无响应.作为解决方案,浏览器将停止似乎花费太长时间的代码,并询问用户是否希望脚本继续运行.

Pages are single threaded, so having a long running script will cause the page to lock up. Browsers like Internet Explorer use a single thread for the entire browser, so that means that the entire browser will become unresponsive. As a solution, browsers will stop code that appears to be taking too long and ask the user if they want the script to continue to run.

Internet Explorer的较旧版本没有特别快的JavaScript引擎,因此迭代100个输入并验证它们将花费很长时间,而使用.each()之类的时间可能更长.即使代码在技术上可以运行,也将花费很长时间.您可能可以做一些事情来优化代码,但是我认为一个简单的解决方案是将事件侦听器附加到每个输入,并在用户输入值时对其进行验证.这将带来双重好处,即用户不必滚动长格式并查找无效字段,并且浏览器一次只能验证一个框.

Older versions of internet explorer don't have especially fast javascript engines, so iterating through 100 inputs and validating them will take a long time, and possibly longer with things like .each(). Even though the code will technically run, it will take a long time. You might be able to do things to optimize your code but a simple solution I think would be to attach an event listener to each of the inputs, and validate them as the user inputs the values. This would have the double benefit of the user not having to scroll through the long form and find the invalid fields and it would allow the browser to only validate one box at a time.

最后,您可能需要考虑将其分解为一个多步骤过程,这可能对可用性很有帮助,并具有在用户走得太远且发生不良情况之前保存状态的附加好处.

Finally, you may want to consider breaking this up into a multi-step process, which might be helpful for usability, and has the added benefit of saving state before the user gets too far along and something bad happens.

这篇关于使用jquery Validate的长格式导致IE缓慢的脚本警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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