本人在看到prop()这个函数比较陌生,于是就学习并改写了这个函数
<!DOCTYPE html><html>
<head>
<meta charset="UTF-8">
<title>添加和删除属性(prop和removeProp)</title>
<script src="./jquery-3.1.0.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
var a=$("div");
a.prop("font-weight","20px");
a.append("font-weight:"+a.prop("font-weight")+"</br>");
a.removeProp("font-weight");
a.append("font-weight:"+a.prop("font-weight")+"</br>");
})
})
</script>
</head>
<body style="background-color:red;color:blue">
<button>add and delete</button>
<div></div>
</body>
运行结果截图:
</html>