图像onload功能在safari和edge中不起作用

问题描述 投票:-1回答:1
imageObj.onload = function() {

imageObj.addEventListener('load', function() {

我想在加载图像时执行代码。我已经尝试了上述两条线,但没有一条线在边缘和野生动物园中工作。在chrome中,它工作正常。

jquery image safari microsoft-edge onload
1个回答
0
投票

我使用下面的代码示例进行了测试,看起来这些代码示例正在使用MS Edge。

<!doctype html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
var img = new Image();
img.onload = function () {
   alert("image is loaded");
}
img.src = "http://pierre.chachatelier.fr/programmation/images/mozodojo-original-image.jpg";

$(img).appendTo('body');
});
</script>
</head>
<body>
</body>
</html>

MS Edge中的输出。

enter image description here

这是另一种方法。

<!DOCTYPE html>
<html>
<body>

<img src="C:\Users\panchals\Desktop\image\9.gif" onload="loadImage()" width="100" height="132">

<script>
function loadImage() {
  alert("Image is loaded");
}
</script>

</body>
</html>

您可以尝试使用这些代码进行测试。如果问题仍然存在,我建议您发布完整的示例代码。我们会尝试检查它。

© www.soinside.com 2019 - 2024. All rights reserved.