js基础图片库

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>我的图片库</title>
  <style>
	#gallery{
	list-style:none;
	}
#gallery li{
	display:inline;
	}
#gallery li a img{
	width:10%;
	}
h1{
	margin-left:35px;
	}
#placeholder,#imgText{
	margin-left:38px;
	}
  </style>
 </head>
 <body>
	<h1>我的图片库</h1>
	<ul id="gallery">
		<li><a href="http://a.niupic.com/images/2014/08/11/53e86de596293.jpg" title="这是第一张图片"><img src="http://a.niupic.com/images/2014/08/11/53e86de596293.jpg"></a></li>
		<li><a href="http://a.niupic.com/images/2014/08/11/53e86de9b1406.jpg" title="这是第二张图片"><img src="http://a.niupic.com/images/2014/08/11/53e86de9b1406.jpg"></a></li>
		<li><a href="http://a.niupic.com/images/2014/08/11/53e86dee0c934.jpg" title="这是第三张图片"><img src="http://a.niupic.com/images/2014/08/11/53e86dee0c934.jpg"></a></li>
		<li><a href="http://a.niupic.com/images/2014/08/11/53e86df3853fb.jpg" title="这是第四张图片"><img src="http://a.niupic.com/images/2014/08/11/53e86df3853fb.jpg"></a></li>
	</ul>
	<img id="placeholder" src="http://a.niupic.com/images/2014/08/11/53e86df54242f.gif">
	<p id="imgText">欢迎来到我的图片库</p>
	<script>
			


function parper(){
	var gallery = document.getElementById("gallery");
	var link = gallery.getElementsByTagName("a");
	for(var i=0; i<link.length; i++){
		link[i].onclick = function(){
			return !showPic(this);	
		}
	}
}






function showPic(which){
	if(!document.getElementById) return false;
	var placeholder = document.getElementById("placeholder");
	var whicher = which.getAttribute("href");
	placeholder.setAttribute("src",whicher);


	var imgText = document.getElementById("imgText");
	var text = which.getAttribute("title");
	imgText.childNodes[0].nodeValue = text;
	return true;
	
}
addLoadEvent(parper);


function addLoadEvent(func){
	var oldonload = window.onload;
	if(typeof window.onload != "function"){
		window.onload =func;
	}else{
		oldonload();
		func();
	}
}
	</script>
</body>
</html>

本人小白,这是第一次上传代码。感谢@pingfan 提供上传图片的网站。 这个小代码源自     js_dom编程艺术。 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值