点(.)属性操作
<!DOCTYPE html>
<html>
<head>
<title>新建网页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
</head>
<body>
<h2>属性值操作</h2>
<p><input type="text" name="username" value="tom" class="orange" id="mingzi" weight='130' /></p>
<p><input type="button" value="获取" onclick="f1()" /></p>
<p><input type="button" value="设置" onclick="f2()" /></p>
</body>
</html>
<script type="text/javascript">
//设置属性值
function f2(){
var it = document.getElementById("mingzi");
it.name = "usermail";
it.value = "jim@163.com";
it.className = "apple";
it.setAttribute("weight",155);
it.type = "checkbox";
}
function f1(){
var it = document.getElementById("mingzi");
console.log(it.type);
console.log(it.name);
console.log(it.className);
console.log(it.id);
console.log(it.getAttribue("weight"));
console.log(it.getAttribute("value"));
}
</script>