Sometimes we need to display the images in the database in batches, and the path of the pictures is of course stored in the database. However, if you find that some pictures do not exist, the Red Cross on the Web page will be very ugly, this time we can choose to display the default image instead, this will appear very humane. Hefeng County Tobacco Monopoly Bureau
The image object's OnError event is used to determine that an error replaces the image object's SRC as the default image URL.
JavaScript onerror Events
Using the OnError event is an old-fashioned standard method of capturing Javascript errors in a Web page.
The OnError event is generated whenever a script error occurs on the page. If you need to take advantage of the OnError event, you must create a function that handles the error. You can think of this function as the OnError event handler (onerror events handler). This event handler uses three parameters to invoke: Msg (error message), URL (the URL of the page where the error occurred), line (the lines of code where the error occurred).
Onerror=handleerrfunction Handleerr (msg,url,l) {//handle The error Herereturn true or false}
Whether the browser displays a standard error message depends on the return value of the onerror. If the return value is False, the error message is displayed in the console (JavaScript console). Conversely, it does not.
The following example shows how to use the OnError event to catch an error:
Show default picture if picture doesn't exist