Jquery find() 在 IE 中花费太多时间
我正在尝试在 Ajax HTML 响应中的 DIV 中查找 HTML:
$j(responseText).find("#my_DIV").html()
这在 FF 中完美运行,但 IE6 似乎挂起并永远等待 find() 完成,是否有解决方法来查找 DIV 或者有什么我可以做的事情我做错了吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为问题在于 jQuery.clean 函数,如果你传递一个非常大的 HTML,一旦 jquery 必须将所有 html 字符串解析为 dom 节点,你的浏览器将有很多工作要做,如 firefox 比 IE 更快 你只注意到 IE 中的问题。
I think the problem is with jQuery.clean function, if you pass a very large HTML you browser will have a lot of work to do once jquery have to parse all html string into dom nodes, as firefox is faster than IE you only notice the problem in IE.
如果是 ajax 调用,请尝试减少响应。您没有提及您在服务器端使用的内容 - 但其想法是,如果传入的是 XMLHttpRequest,则您只返回所需的片段。
If it's an ajax call try to trim down the response. You don't mention what you're using on the server side - but the idea is that if it's an XMLHttpRequest coming in you return just the fragment that's needed.
尝试像这样拆分您的代码:
这样,您将能够准确地看到哪一部分花费了时间。然后,有了更准确的信息,您可以编辑您的问题以提供更多详细信息。
Try splitting up your code like this:
This way, you'll be able to see precisely which part is taking the time. Then, with that more accurate information, you can edit your question to provide more details.
我不确定后代选择器是否使用与 find 方法相同的迭代,但您可以尝试以下代码来查看是否获得更快的响应:
请参阅 后代选择器
I am not sure whether the descendant selector uses the same iteration as the find method, but you can try the following code to see if you get any faster responses:
See the documentation for the descendant selector