重點(diǎn):
//.prop('')方法:用于選中元素的固有屬性
//.removeProp('')方法:用于消除元素的固有屬性
//.prop('data-mation','寶寶啊寶寶'):用于增加一個(gè)自定義的屬性,且給屬性賦予一個(gè)值
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<body>
<img src="img/001.jpg"/ alt="寶寶頭像">
</body>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var res=$('img').prop('alt')
//變量res=jq對(duì)象img中固有屬性alt
var res= $('img').removeProp('alt')
var res= $('img').prop('data-mation','寶寶啊寶寶')
//利用'data'方式寫入的,僅是增加了一個(gè)自定義元素,作為臨時(shí)數(shù)據(jù)儲(chǔ)存
console.log(res)
</script>
</html>
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)