js加载图片失败,怎样替换为默认图片

JavaScript023

js加载图片失败,怎样替换为默认图片,第1张

段代码是判断图片是否加载成功,如果不成功则自动加载默认图片(notimg.gif);可是在火狐下不好使,只支持IE if(document.location.href.indexOf('fromTask1')>0) {

resizeSearchTaskDiv()

var searchTask = get("s_search_task")

searchTask.show()

var resetPositonEvent = resizeSearchTaskDiv.bind(searchTask)

Zhishi.Event.attachEventListener(window,'resize',resetPositonEvent)

}

get('sb').value= text

get('sb').select()

get('sb').focus()

Zhishi.Event.attachEventListener(get('sb'),'click',function(){

if(get(' www.wjfkzj.com ').value.trim()==text) {

get('sb').value=''

get("s_search_task").hide()

}我看 了,你应该想我这样写,我看了上面的代码你路径好想是出错误了,所以你现在把我的复制下就行了把给个满意答案啊!!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>

<HEAD>

<TITLE>New Document </TITLE>

<META NAME="Generator" CONTENT="EditPlus">

<META NAME="Author" CONTENT="">

<META NAME="Keywords" CONTENT="">

<META NAME="Description" CONTENT="">

</HEAD>

<script>

var i=1

var j=0

var front

var after

var arr = new Array("p1.jpg","p2.jpg","p3.jpg","p4.jpg","p5.jpg","p6.jpg","p7.jpg","p8.jpg","p9.jpg","p10.jpg","p11.jpg","p12.jpg","p13.jpg","p14.jpg","p15.jpg","p16.jpg","p17.jpg","p18.jpg","p19.jpg","p20.jpg","p21.jpg","p22.jpg","p23.jpg")

//下一张

function down(){

if(j==0){

i++

if(i>arr.length-1){

i=0

}

}document.photos.src=arr[i]

}

//上一张

function up(){

if(j==0){

i--

if(i<0){

i=arr.length-1

}

}document.photos.src=arr[i]

}

//自动滚动

function automatism(){

window.clearInterval(after)

front = window.setInterval("down()",1000)

}

//反向自动切换

function reverse(){

window.clearInterval(front)

after=window.setInterval("up()",1000)

}

//暂停

function pause(){

window.clearInterval(front)

window.clearInterval(after)

}

</script>

<BODY>

<img src="p2.jpg"name="photos"></p>

<input type="button" value="上一张" onClick="up()">

<input type="button" value="自动滚动" onClick="automatism()">

<input type="button" value="反向滚动" onClick="reverse()">

<input type="button" value="暂停" onClick="pause()">

<input type="button" value="下一张" onClick="down()">

</BODY>

</HTML>

建个html文件,把这段代码放进去,跟图片放一起,试一下,希望对你有帮助

不知道 你用什么语言开发的,有两种方法:1、在页面展示时判断 从数据库里读取的字段是否为空,若为空则展示默认的图片路径;2、展示的数据肯定是从数据库里读取,在存之前判断下有没有图片,若没有则把默认的图片路径存到数据库里,页面读取 时肯定显示默认图片了。嘿嘿