我是来自意大利的奥古斯托
从 HTML 迁移到 XHTML 时,我遇到了一个 Unresolved 问题
在html代码中,我有一个图像(bigimg),它首先通过由body onload充电的Js充电,然后预览系列之外的其他图像被充电,从而替换我的图像,
正文:
<body onload="...........;viewimgac('images/accessories/img01cs.jpg');...............">
功能是:
// the waiting image view and the main image loading is managed
function elaboraimgac(urlimg) {
document.getElementById('dattesa').style.filter = "alpha(opacity:"+90+")";
document.getElementById('dattesa').style.MozOpacity = 90/100;
document.getElementById('dattesa').style.KHTMLOpacity = 90/100;
document.getElementById('dattesa').style.opacity = 90/100;
MM_changeProp('dattesa','','style.visibility','visible','LAYER'); // div is made visible through the waiting gift.
document.getElementById('bigimgid').src = urlimg; // I load the image
代码页显示:
<img src="#" id="bigimgid" style="position:absolute;left:0px;top:0px;" onload="finecaricimg()" alt="" />
<img>
标签本身会阻止 XHTML 验证。我必须消除 onload="finecaricimg()",该函数允许使用加载后可用的图像大小适当放置在页面中的 ImageView 。
我这样做:
1) 更改 <img
标签
<img src="#" id="bigimgid" style="position:absolute;left:0px;top:0px;" alt="" />
2)我添加:
function elaboraimgac(urlimg) {
//to Js elaboraimgac function
//........
//........
document.getElementById('bigimgid').onload = finecaricimg(); // the specific function is called after loading
}
拦截图片加载结束并调用加载结束函数
不幸的是,该过程没有成功。通过警报,我意识到当加载端充电时图像大小为零,就好像 finecaricimg()
在 .src 处理后立即收费,而不是在图像加载结束时收费。
我尝试添加:
document.getElementById('bigimgid').src = urlimg;alert("AAAAA"); // load image
然后,当出现警报窗口时,我等待几秒钟,然后单击“确定”。这样,图像尺寸正确并且图像正确放置在页面中。 我无法理解,因为代码似乎是正确的。 因此,我征求您的建议。
最佳答案
....onload = finecaricimg();
您刚刚立即调用函数并将其结果分配给onload
(就像任何其他函数调用一样)。
您想要分配函数本身,而不是调用它。
关于javascript - 我无法验证标签 img,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25937749/