jQuery本身没有,jQuery用于快捷的便利所有 img 标签。img标签对象,有一个属性,叫做:readyState,取值如下: uninitialized: Object is not initialized with data. loading: Object is loading its data. loaded: Object has finished loading its data. interactive: User can interact with the object even though it is not fully loaded. complete: Object is completely initialized. 检测主要靠这个,类似于: counter = 0; $("img").each(function(){ if (this.readyState==loaded || this.readyState==complete) counter++; }); if (counter >= 10) alert("所有图片装载完毕!");另一种做法,是给所有<img>增加onload事件,在onload事件中,给计数器做累加,达到一定数量则判定为全部图片装载完毕
<head>
<title></title>
<script>
window.onload=function(){
alert(1234);
};
</script>
</head>
<body></body>
</html>
jQuery本身没有,jQuery用于快捷的便利所有 img 标签。img标签对象,有一个属性,叫做:readyState,取值如下:
uninitialized: Object is not initialized with data.
loading: Object is loading its data.
loaded: Object has finished loading its data.
interactive: User can interact with the object even though it is not fully loaded.
complete: Object is completely initialized. 检测主要靠这个,类似于:
counter = 0;
$("img").each(function(){
if (this.readyState==loaded || this.readyState==complete) counter++;
});
if (counter >= 10) alert("所有图片装载完毕!");另一种做法,是给所有<img>增加onload事件,在onload事件中,给计数器做累加,达到一定数量则判定为全部图片装载完毕
下载后记得评论,把1分挣回来,别浪费了。
当然是 dom 对象属性,<img> 就是个dom对象
$(function()
{
$("#query").click(function()
{
$("#main").empty();
this.disabled = true;
$.post("QueryImageServlet",
{
keyword:$("#keyword").val(),
picSource: $("input[name=picSource]:checked").val()
},function(respData)
{
var html = "";
var count = 0;
for(var i=0;i<respData.length;i++) {
html += "<img src='" + respData[i] +"' width='200px' height='200px'/>";
};
$("#main").append($(html));
$("#main").show();
$("#main img").each(function(){
if(this.readyState == "loaded" || this.readyState == "complete")
count++;
});
alert(count);
if(count == respData.length) {
$("#query")[0].disabled = false;
}
});
});
$("#main").hide();
});<div id="header">
<input type="text" id="keyword" size="40"/> <input type="button" value="Submit" id="query">
<input type="button" value="Save" width="40px" id="download"/>
<input type="radio" name="picSource" value="google" checked><font size="5px">Google</font> <input type="radio" name="picSource" value="flickr"><font size="5px">Flickr</font>
</div>
<div id="main">
这里一显示maindiv我就去判断img是否加载完成,此时img都是未装载完成的所有count都是0,那什么时候去判断img是否装载完成了,div未上是否也可以用onload来判断里面内容是否装载成功?