我可以想到可能发生这种情况的几个原因。
- The images may not yet be completely loaded at the time the code runs.
- Your images may not be direct children of the element matching your class.
- Your code may be running before the document is loaded and nothing matches the class yet.
My best guess is (1), in which case you should add a load handler for the images that does what you want when the image completes loading. Running the code on both document load and image load is probably in order in case the image is cached and the load event for it fires before the image load handler is applied. Image load would be necessary if the image is replaced dynamically after the document has been loaded.
www.un.org/Depts/DGACM/index_spanish.htm 你们应当在当地对我的行程进行勘测,以避免对全球名称空间进行污染(以及由于范围问题而可能造成的ug)。
$(document).load( function() {
var maxxxHeight = $(window).height();
$(".theImage").children( img ).each(function() {
$(this).load( function() { // only if images can be loaded dynamically
handleImageLoad(this);
});
handleImageLoad(this);
});
function handleImageLoad(img)
{
var $img = $(img), // declare local and cache jQuery for the argument
myHeight = $img.height();
if ( myHeight > maxxxHeight ){
// this is where your real code would go to make adjustments, etc.
$img.next().text("Browser " + maxxxHeight + " image height " + myHeight);
};
}
});