<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
	<style type="text/css">
		span{
			color:#a00;
		}
	</style>
</head>
<body>
	<a href="https://api.fnkr.net/testimg/100x100/a00/FFF/?text=A"><img src="https://api.fnkr.net/testimg/100x100/a00/FFF/?text=A"></a>
	<a href="https://api.fnkr.net/testimg/100x100/0a0/FFF/?text=B"><img src="https://api.fnkr.net/testimg/100x100/0a0/FFF/?text=B"></a>
	<a href="https://api.fnkr.net/testimg/100x100/00a/FFF/?text=C"><img src="https://api.fnkr.net/testimg/100x100/00a/FFF/?text=C"></a>
	<h2>cache[<span id="srcforindex"></span>].$img.attr('src')的值是<span id="src"></span></h2>
	<script type="text/javascript">
		var cache={};
		$(document).on('click','a',function(e){
			var $img;
			var src = this.href;
			e.preventDefault();
			$img=$('<img/>');
			cache[src]={
				$img:$img,
				isLoading:false
			};
			/*不用透過cache這個物件去定義,也可以影響到裡面的值*/
			$img.attr({
				'src':src
			});
			$('#srcforindex').text(src);
			$('#src').text(cache[src].$img.attr('src'));
		});
	</script>
</body>
</html>
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Jerry 的頭像
    Jerry

    Bug倉庫 // 程式日記

    Jerry 發表在 痞客邦 留言(0) 人氣()