jquery html回调 [英] jquery html callback
问题描述
有一个回调的html()函数或一种方法来检查它是否完成。例如:
$(#some_div)。html('something here');
if($(#some_div)。html()==''){
// do something here
}
我设置一个元素的html从一个帖子。有时它不负载,所以当它不负载我想要它做某事,这是可能的。我现在的方式,它总是做另一件事,因为它hasnt设置html的时候它检查它有html。
html()
是同步操作。 DOM的实际更新取决于您的html内容。如果您有< img>
或< iframe>
标记,则需要一些时间才能加载。 html()
后面的下一个语句应该会立即看到新的html内容。
根据您的评论,这可能是您的 $。ajax 失败。不是 Is there a callback for the html() function or a way to check that it is finished. For example: I am setting the html of an element from a post. Sometimes it doesnt load so when it doesnt load I would like for it to do something, is this possible. The way I have it now it always does the other thing because it hasnt set the html by the time it checks that it has html. Did you mean [Edit] Based on your comment, it is probably your 这篇关于jquery html回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! html()
。尝试附加一个失败处理程序到ajax调用,并从那里重试?虽然,如果你的服务器端代码以200代码静默失败,失败事件不会被调用。在这种情况下,您可以在将html值设置为元素之前验证该值。$("#some_div").html('something here');
if($("#some_div").html() == ''){
//do something here
}
html()
is a synchronous operation. The actual updating of the DOM depends on what your html content is. If you have <img>
or <iframe>
tags, they will take time to load. The next statement following the html()
should immediately see the new html contents.load()
instead?$.ajax
failing. Not html()
. Try attaching a failure handler to ajax call and retry from there? Although, if your server side code silently fails with a 200 code, the failure event doesn't get called. In that case, you can validate the html value before you set it to the element.