<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>无标题文档</title>
<style type="text/css">
.navboxcont_77E711 { width: 1028px; height:701px}
.navboxauto_6B6CBB { margin-left:150px;width:auto; height:23px}
#leftright, #topdown{position:absolute;left:0;
top:0;width:1px;height:1px;layer-background-color:red;
background-color:red;z-index:100;font-size:1px;}
</style>
<script type="text/javascript">
function Search(){
document.getElementById("img1").src = "images/" + document.getElementById("txt").value + ".png";
}
</script>
</head>
<body>
<div class="navboxauto_6B6CBB"><input type="text" id="txt" size="49" value="请输入股票代码"onclick="this.value='';" />
<input type="button" value="搜<>索" onclick="Search()" /></div>
<br><div class="navboxcont_77E711"><img src="images/600000.png" id="img1" /></div></br><div id="leftright" style="width:expression(document.body.clientWidth-2)"></div><div
id="topdown" style="height:expression(document.body.clientHeight-2)"></div>
<script>
<!--
if (document.all&&!window.print){
leftright.style.width=document.body.clientWidth-2
topdown.style.height=document.body.clientHeight-2
}
else if (document.layers){
document.leftright.clip.width=window.innerWidth
document.leftright.clip.height=1
document.topdown.clip.width=1
document.topdown.clip.height=window.innerHeight
}
function followmouse1(){
//move cross engine for IE 4+
leftright.style.pixelTop=document.body.scrollTop+event.clientY+1
topdown.style.pixelTop=document.body.scrollTop
if (event.clientX<document.body.clientWidth-2)
topdown.style.pixelLeft=document.body.scrollLeft+event.clientX+1
else
topdown.style.pixelLeft=document.body.clientWidth-2
}
function followmouse2(e){
document.leftright.top=e.y+1
document.topdown.top=pageYOffset
document.topdown.left=e.x+1
}
if (document.all)
document.onmousemove=followmouse1
else if (document.layers){
window.captureEvents(Event.MOUSEMOVE)
window.onmousemove=followmouse2
}
function regenerate(){
window.location.reload()
}
function regenerate2(){
setTimeout("window.onresize=regenerate",400)
}
if ((document.all&&!window.print)||document.layers)
window.onload=regenerate2
//-->
</script>
</body>
</html>
现在在输入框输入代码,点击“搜索”可以找到相应的图片,不过我输入的代码不正确,如我输入了“600002”但images里没有这个图片,现在输入不正确的结果就是一个小x,现在想让图片框里显示“请输入正确的代码”或者显示images/gghh.png个图片也可以,不过还是显示“请输入正确的代码”节省资源,反正哪个都行,该怎么改

解决方案 »

  1.   

    <img onerror="this.src='error.gif'"
      

  2.   


    <div id='div1' class="navboxcont_77E711"><img src="images/600000.png" id="img1" /></div>
    function Search(){
    var b=查找结果;
    if(b)
    document.getElementById("div1").innerHTML = "<img src='images/'" + document.getElementById('txt').value + ".png />";
    else
    document.getElementById("div1").innerHTML="请输入正确的代码!";
    }
      

  3.   

    document.getElementById("img1").onreadystatechange=function(){
     if (document.getElementById("img1").readyState=="complete") {
    alert("图片存在");
    }
    else
    {
    alert("图片不存在");
    }
    };
    在Search()里面加上它 你就知道怎么做了
      

  4.   

    1楼:
    <img src="images/600000.png" id="img1" />
    to
    <img src="images/600000.png" id="img1" onerror="this.src='images/gghh.png' />2楼:
    var b=查找结果;
    "查找结果"要换成你自己的查找结果。