首页 > 代码库 > HTML 商品展示(js)

HTML 商品展示(js)

利用Object.indexOf(“.”)返回.的下标

在用Object.substr(star,lengh)返回指定长度字符串。star是开始位置,length是截取长度;

————————————————————————————————————————————————————————

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>商品展示</title>
<style type="text/css">
#id1{
width:248px;
height:248px;
}
img{
display:block;
float:left;
margin-left:0px;
width:40px;
height:40px;
padding:5px;
border:1px solid #CCC;
}

</style>

</head>

<body>
<div style="width:300px; margin:5% auto">
<img id="id1" src="http://www.mamicode.com/imange/show1_big.jpg"><br>

<img src="http://www.mamicode.com/imange/show1.jpg">
<img src="http://www.mamicode.com/imange/show2.jpg">
<img src="http://www.mamicode.com/imange/show3.jpg">
<img src="http://www.mamicode.com/imange/show4.jpg">
<img src="http://www.mamicode.com/imange/show5.jpg">
<div>
</body>
<script type="text/javascript">
var imgg=document.getElementsByTagName("img");
for(var i=1;i<imgg.length;i++){
imgg[i].onmouseover=function(){
var a=this.src;
var i=a.indexOf(".");
var x=a.substr(0,i);
document.getElementById("id1").src=http://www.mamicode.com/x+"_big.jpg";

imgg[i].onmouseout=function(){
document.getElementById("id1").src="http://www.mamicode.com/imange/show1_big.jpg";
this.style.border="1px solid #CCC";
}
}
</script>
</html>

HTML 商品展示(js)