Blogger Information
Blog 35
fans 2
comment 0
visits 22618
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
attr()和css()及常见样式函数--2018年4月8日11时30分
小学僧的博客
Original
621 people have browsed it

常见样式和属性设置函数代码如下:

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
		.box1{
			width: 200px;
			height: 200px;
			background-color: lightgray;
			display: table-cell;
			vertical-align: middle;
			border-radius: 4px;			
			box-shadow: 2px 2px 2px #888;
		}
		.box2{
			width: 120px;
			height: 120px;
			background-color: gray;
			margin: auto;
			border-radius: 7px;
		}
	</style>
	<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
	<div class="box1">
		<div class="box2"><img class="pic" src="https://www.llheng.com/img/img/boy.jpeg" width="100" alt="test" title="animal"></div>
	</div>
</body>
</html>
<script type="text/javascript">
	var s = $('img').attr('src')
	var s = $('.pic').attr({
		"width":"120",
		"style":"box-shadow:2px 2px 2px #888"
	})
	var s = $('.pic').attr('title',function(){
		return 'lovely'
	})


	var s = $('.box1').css('background-color')
	var s = $('.pic').css({
		"box-shadow":"3px 3px 3px #888",
		"border-radius":"7px"
	})
	
	var s = $('.box2').width()
	var s = $('.box1').height()
	var s = $('.box2').offset().top
	var s = $('.pic').position().top
	//console.log(s)
</script>

运行实例 »

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

手写css方法如下:

3.jpg

总结:

css()和attr()类似类似,当参数只有一个时,函数的作用是获取参数属性的值,当参数为2个值时,作用是设置相应的参数,如果设置的属性值有多对,用{}包含,用逗号隔开。

Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post