特性
特性:attributes:值为string
属性
属性:properties:值为string、boolean、number、object;
区分
属性能获取值,特性获取不了
<!DOCTYPE html>
<html lang="en">
<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>
<script src="../Jquery/jquery-3.3.1/jquery-3.3.1.js"></script>
<script src="../Jquery/jquery-3.3.1/jquery-3.3.1.min.js"></script>
</head>
<body>
<img id="logo" src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3142343904,631493091&fm=26&gp=0.jpg" title="CSDN logo" alt="Jquery logo" class="img-jquery" >
<input type="checkbox" id="check" tabindex="1" style="width: 50px; height: 50px;"
title="Check this!" description ="just a checkbox" />
<script>
$(function () {
function byid(id) {
return typeof(id) === "string" ?document.getElementById(id) : id;
}
//var img =document.getElementById("logo");
// 打印img特性
//console.log(img.attributes);
// 获取img的class的特性的值 (特性的值都是字符串)
//console.log(img.getAttribute('class'));
var checkbox = byid("check");
//打印icheckbox.tabindex特性
console.log(checkbox.getAttribute("tabindex"));
// 获取属性值(与楼上颜色不一样)
console.log(checkbox.tabIndex);
// 返回值
console.log(checkbox.getAttribute('style'));
// 返回对象,对象里包t含所有属性
console.log(checkbox.style);
})
</script>
</body>
</html>