博客列表 >jquer 自定义属性和样式的操作

jquer 自定义属性和样式的操作

大熊的php博客
大熊的php博客原创
2018年04月11日 18:38:57470浏览

代码

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>



</head>
<body>
<div class="box">
	<img  src="./images/1.jpg" width="200" alt="美女" title="明星" id="pic" data-nation="中国">


</div>
</body>

<script type="text/javascript">

// 当传递两个参数的时候是设置他的属性


// 当传递一个参数的时候是读取他的属性

// var res=$('img').attr("src")
$('img').attr("height","180px")

// 设置自定义属性然后变动覆值,不能删除原声属性
 $('img').prop('data-nation','中国山东')
 var res = $('img').prop('data-nation')

$('img').addClass('')

	var res = $('img').css({
		'width': '200',
		'border-radius': '10%',
		'box-shadow': '3px 3px 3px #888'
	})



console.log(res)







</script>
</html>

运行实例 »

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


结果

36.jpg



声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议