简体   繁体   English

Javascript onerror事件不起作用

[英]Javascript onerror event is not working

i'm making an admin portal where admin can create users,and when they create user they only add their basic details. 我正在创建一个管理员门户,管理员可以在其中创建用户,当他们创建用户时,他们只会添加其基本详细信息。 so when a user logs in to the system he finds a broken image. 因此,当用户登录系统时,他发现损坏的图像。 to fix that i did some digging and found out about onerror event in img tag. 解决我进行了一些挖掘并发现了img标签中的onerror事件的问题。 I tried using it,but it is not working. 我尝试使用它,但是它不起作用。

my code : <img src="images/<?php echo $image;?>" onError="this.onerror=null;this.src='/images/abc.png';"/> 我的代码: <img src="images/<?php echo $image;?>" onError="this.onerror=null;this.src='/images/abc.png';"/>

Please help me out here,this is the only task remaining to finish of my 1st project. 请在这里帮助我,这是完成我的第一个项目的唯一任务。

As mentioned, you can use PHP to check if the image exists and replace it server-side. 如前所述,您可以使用PHP来检查映像是否存在并在服务器端将其替换。 To answer your question about the image onerror function, see: jQuery/JavaScript to replace broken images 要回答有关图像onerror函数的问题,请参阅: jQuery / JavaScript替换损坏的图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM