主题:[讨论]如何实现某缩略图获得焦点后出现大图(onfocus代替onclick)
<SCRIPT language=javascript>
function replaceImg(sourceUrl,imgUrl) {
if(document.all.mainpic.src == sourceUrl){
return;
}
var img = new Image();
img.src = sourceUrl;
if(img.width>280){
img.height=img.height/(img.width/280);
img.width=280;
}
var elem = document.getElementById("mainpic");
elem.width = img.width;
elem.height = img.height;
elem.src = sourceUrl;
document.getElementById("mainPicUrl").href = "" + imgUrl;
}
</SCRIPT>
缩略图代码:
<img style=""CURSOR: hand"" onclick="javascript:replaceImg('01.gif','01.gif')" src="01.gif" onload="javascript:if(this.height>this.width){this.height=80}else{this.width=80}" border="1">
<img style=""CURSOR: hand"" onclick="javascript:replaceImg('02.gif','02.gif')" src="02.gif" onload="javascript:if(this.height>this.width){this.height=80}else{this.width=80}" border="1">
<img style=""CURSOR: hand"" onclick="javascript:replaceImg('03.gif','03.gif')" src="03.gif" onload="javascript:if(this.height>this.width){this.height=80}else{this.width=80}" border="1">
<img style=""CURSOR: hand"" onclick="javascript:replaceImg('04.gif','04.gif')" src="04.gif" onload="javascript:if(this.height>this.width){this.height=80}else{this.width=80}" border="1">
全图代码:
<A id="mainPicUrl" onfocus="this.blur()" href="01.gif" target="_blank"><img id="mainpic" style="cursor: hand" src="01.gif" onload="javascript:if(this.height>this.width){this.height=280}else{this.width=280}" border="1" style="border-style: solid; border-color: #000000; padding: 1"></A>
现在想用onfocus触发,怎么实现?[em10]
function replaceImg(sourceUrl,imgUrl) {
if(document.all.mainpic.src == sourceUrl){
return;
}
var img = new Image();
img.src = sourceUrl;
if(img.width>280){
img.height=img.height/(img.width/280);
img.width=280;
}
var elem = document.getElementById("mainpic");
elem.width = img.width;
elem.height = img.height;
elem.src = sourceUrl;
document.getElementById("mainPicUrl").href = "" + imgUrl;
}
</SCRIPT>
缩略图代码:
<img style=""CURSOR: hand"" onclick="javascript:replaceImg('01.gif','01.gif')" src="01.gif" onload="javascript:if(this.height>this.width){this.height=80}else{this.width=80}" border="1">
<img style=""CURSOR: hand"" onclick="javascript:replaceImg('02.gif','02.gif')" src="02.gif" onload="javascript:if(this.height>this.width){this.height=80}else{this.width=80}" border="1">
<img style=""CURSOR: hand"" onclick="javascript:replaceImg('03.gif','03.gif')" src="03.gif" onload="javascript:if(this.height>this.width){this.height=80}else{this.width=80}" border="1">
<img style=""CURSOR: hand"" onclick="javascript:replaceImg('04.gif','04.gif')" src="04.gif" onload="javascript:if(this.height>this.width){this.height=80}else{this.width=80}" border="1">
全图代码:
<A id="mainPicUrl" onfocus="this.blur()" href="01.gif" target="_blank"><img id="mainpic" style="cursor: hand" src="01.gif" onload="javascript:if(this.height>this.width){this.height=280}else{this.width=280}" border="1" style="border-style: solid; border-color: #000000; padding: 1"></A>
现在想用onfocus触发,怎么实现?[em10]