博主信息
博文 59
粉丝 0
评论 1
访问量 58028
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
​jQurey attr与CSS方法实例——2018年4月8日11时15分
白猫警长的博客
原创
769人浏览过

jQurey  attr与CSS方法实例

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
	.pos{
		width: 1000px;
		height: 100%;
		text-align: center;
		margin:50px auto;

	}
	</style>
</head>
<body>
	<div class="pox">
		<button class="but1">点击更换图片</button>
		<button class="but2">点击修改尺寸</button><br>
		<img src="http://pic1.nipic.com/2008-10-20/2008102011212258_2.jpg" title="细水长流" id="imar" >
		
	</div>
</body>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
	<script>
	$('.pox').addClass('pos')
		//传入2参数后改变原生属性的值
	$('#imar').attr('title','交友魅力,随心所欲')

	

	$('#imar').attr('alt','不是你的,你看不见')

	$('.but1').click(function(){
	$('#imar').attr('src','http://pic11.photophoto.cn/20090528/0010023912902949_b.jpg')
	})

	$('.but2').click(function(){
		$('#imar').width('200px')
		$('#imar').height('200px')
	})
	// 按钮的宽度
	$('.but1').width(80).height(35)
	$('.but2').width(80).height(35)

	$('#imar').css({
		'width':'300',
		'height':'400',
		'border':'1px solid #808080',
		'border-radius':'50%',
		'box-shadow':'5px 5px 5px #888',
		'margin-top':'30px'
	})

	$('#imar').offset().left
	alert('图片与左侧的距离是:'+$('#imar').offset().left +'px')
	$('#imar').offset().top
	alert('图片与顶部的距离:'+$('#imar').offset().top +'px')
	
	$('#imar').position().left
	alert('左侧偏移量是:'+$('#imar').position().left +'px')
	$('#imar').position().top
	alert('顶部偏移量是:'+$('#imar').position().top +'px')

</script>
</html>

运行实例 »

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


运行后效果预览图:

1.png


当你点击相应的按钮后,就会发生变化,运行一下试试吧。

手抄作业:

QQ图片20180408111946.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+教程免费学