Automatically replace the page failure picture

xiaoxiao2021-04-07  361

I saw a friend asked this question in a classic, of which XLING big brother gave a solution: , but if there is a large number of pictures in the web page, the workload is great. Even if you want to write a function to automatically update all the failure images of the page.

Basic thinking is to traverse the picture in the page. If the failure is found to automatically replace the preset picture. The code is as follows (this time is more useful code):

DOCTYPE HTML PUBLIC "- // w3c // DTD XHTML 1.0 Transitional // En" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"

>

<

HTML

XMLNS

= "http://www.w3.org/1999/xhtml"

XML: LANG

= "en"

LANG

= "en"

>

<

HEAD

>

<

Title

>

Title

>

<

Script

Type

= "Text / JavaScript"

>

FUNCTION

Disperrimg () {

VAR

IMGS

=

Document.getlementsBytagname

"

IMG

"

);

for

(

VAR

i

=

0

i

<

IMGS.LENGTH; I

) IMGS [i] .onerror

=

IMGS [i] .src

=

"

http://www.blueidea.com/ArticleImg /usericon/xling.gif

"

}

Script

>

HEAD

>

<

Body

>

<

Div

id

= "a"

>

Div

>

<

IMG

SRC

= "AAA.GIF"

Width

= "200"

HEIGHT

= "100"

/>

<

IMG

SRC

= "BBB.GIF"

Width

= "200"

HEIGHT

= "100"

/>

<

IMG

SRC

= "ccc.gif"

Width

= "200"

HEIGHT

= "100"

/>

<

IMG

SRC

= "http://www.blueidea.com/ArticleImg/Usericon/xling.gif"

Width

= "200"

HEIGHT

= "100"

/

>

<

Script

Type

= "Text / JavaScript"

>

Disperrimg ();

Script

>

HTML

>

转载请注明原文地址:https://www.9cbs.com/read-132657.html

New Post(0)