博主信息
博文 71
粉丝 1
评论 1
访问量 102181
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
404--JQ之内联CSS和attr
小威的博客
原创
909人浏览过
  • 效果图

    404.jpg

  • 源代码

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>attr()和removeAttr()练习</title>
	</style>
</head>
<body>
	<div>
	<h2>中国武打明星册</h2>
	<div>
	<img src="http://y.photo.qq.com/img?s=sk8VFhJgl&l=y.jpg" width="200" height="300" alt="功夫" title="中国武打明星前五名" id="imgs" data-nation="中国香港">
	</div>
	<p>
	<button id="bt1">李小龙</button>
	<button id="bt2">成龙</button>
	<button id="bt3">李连杰</button>
	<button id="bt4">吴京</button>
	<button id="bt5">赵文卓</button>
	<br>
	<button id="bt6">返回首页</button>
	<button id="bt7">图片放大</button>
	<button id="bt8">查看原图</button>
	<button id="bt9">主要作品</button>
	<br>
	<button id="bt10">查看图片位置</button>
	<button id="bt11">查看图片偏移值</button>
	</p>
	</div>

</body>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
	// 写基本样式
	$('div:first').css({
		'width': '320',
		'height': '600',
		'background-color': '#f5f5f5',
		'border': '2px solid #708090',
		'margin': '20px auto',
		'text-align': 'center',
		'color': 'blue',
		'box-shadow': '3px 3px 3px #333'
	})
	$('div:eq(1)').height(400)
	$('p').css('line-height','35px')
    // 直接替换相应的图片
	$(document).ready(function(){
  			$("#bt1").click(function(){
	        $('#imgs').attr('src', 'http://y.photo.qq.com/img?s=ok476Jghg&l=y.jpg') 
	        $('#imgs').attr('style', 'border-radius: 50%;box-shadow:2px 2px 2px #888') 
	        $('#imgs').attr('title','《精武门》,《猛龙过江》,《唐山大兄》,《死亡塔》...')
	    });
  			$("#bt2").click(function(){
	        $('#imgs').attr('src', 'http://y.photo.qq.com/img?s=YdvMS1ux9&l=y.jpg') 
	        $('#imgs').attr('style', 'border-radius: 50%;box-shadow:2px 2px 2px #888') 
	        $('#imgs').attr('title','《警察故事》,《尖峰时刻》,《神话》,《十二生肖》...')
	    });
  			$("#bt3").click(function(){
	        $('#imgs').attr('src', 'http://y.photo.qq.com/img?s=5sDD1HQ6S&l=y.jpg') 
	        $('#imgs').attr('style', 'border-radius: 50%;box-shadow:2px 2px 2px #888') 
	        $('#imgs').attr('title','《英雄》,《霍元甲》,《少林寺》,《方世玉》...')
	    });
  			$("#bt4").click(function(){
	        $('#imgs').attr('src', 'http://y.photo.qq.com/img?s=8gSqL0Xxn&l=y.jpg') 
	        $('#imgs').attr('style', 'border-radius: 50%;box-shadow:2px 2px 2px #888') 
	        $('#imgs').attr('title','《太极宗师》,《战狼》,《功夫小子闯情关》,《男儿本色》...')
	    });
  			$("#bt5").click(function(){
	        $('#imgs').attr('src', 'http://y.photo.qq.com/img?s=WqgqGyj8W&l=y.jpg') 
	        $('#imgs').attr('style', 'border-radius: 50%;box-shadow:2px 2px 2px #888') 
	        $('#imgs').attr('title','《风云》,《英雄郑成功》,《断刀客》,《苏乞儿》...')
	    });
  			$("#bt6").click(function(){
	        $('#imgs').attr('src', 'http://y.photo.qq.com/img?s=sk8VFhJgl&l=y.jpg') 
  			$('#imgs').removeAttr('width style')
  			$('#imgs').attr('title','中国武打明星前五名')
	    });
  			$("#bt7").click(function(){
  			$('#imgs').attr({
  				'width':'300',
  				'height':'400'
  			})
	    });
  			$("#bt8").click(function(){
  			$('#imgs').removeAttr('width style')
  		});
  			$("#bt9").click(function(){
  			alert("主要作品:"+$("#imgs").attr("title"))
  		});
  			$("#bt10").click(function(){
  			alert($('img').offset().left+'px')
  			alert($('img').offset().top+'px')
  		});
  			$("#bt11").click(function(){
  			alert($('div:eq(1)').position().left+'px')
  			alert($('div:eq(1)').position().top+'px')
  		});
    });  
</script>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

  • 手抄图

1.jpg

批改状态:未批改

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学