JavaScript方法和技巧大全——图像
2010-09-14 13:39:58 来源:WEB开发网读取图像属性
1<img src=http://tech.ddvip.com/2009-02/"/”image1.jpg"” name=”myImage”>
2<a href=”# ” onClick=”window.alert(document.myImage.width)”>Width</a>
动态加载图像
1<script language=”JavaScript”>
2 myImage = new Image;
3 myImage.src = “Tellers1.jpg”;
4</script>
简单的图像替换
1<script language=”JavaScript”>
2 rollImage = new Image;
3 rollImage.src = “rollImage1.jpg”;
4 defaultImage = new Image;
5 defaultImage.src = “image1.jpg”;
6</script>
7 <a href="/”myUrl"” onMouseOver=”document.myImage.src = rollImage.src;”
8 onMouseOut=”document.myImage.src = defaultImage.src;”>
9 <img src=http://tech.ddvip.com/2009-02/"/”image1.jpg"” name=”myImage” width=100 height=100 border=0>
随机显示图像
1<script language=”JavaScript”>
2 var imageList = new Array; 3: imageList[0] = “image1.jpg”;
3 imageList[1] = “image2.jpg”;
4 imageList[2] = “image3.jpg”;
5 imageList[3] = “image4.jpg”;
6 var imageChoice = Math.floor(Math.random() * imageList.length);
7 document.write(‘<img src=”’ + imageList[imageChoice] + ‘“>’);
8</script>
Tags:JavaScript 方法 技巧
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接