一、js操做element對象
<input type="text" name="uNamesss" id="id1" value="abc"/>
<ul id="ul2">
<li>uk</li>
<li>usa</li>
</ul>
<script type="text/javascript">
//獲取到ul下面的子元素
var ul2 = document.getElementById("ul2");
var arr = ul2.childNodes;
alert("length1: "+arr.length);// 2
var arr1 = ul2.getElementsByTagName("li");
alert("length2: "+arr1.length); //2
//獲取到input
var inputs = document.getElementById("id1");
alert(inputs.value); //abc
alert(inputs.getAttribute("name"));//uNamesss
//setAttribute
alert(inputs.getAttribute("class")); //null
inputs.setAttribute("class","haha");
alert(inputs.getAttribute("class"));//haha
//removeAttribute
alert(inputs.getAttribute("name"));//uNamesss
inputs.removeAttribute("name");
alert(inputs.getAttribute("name"));//顯示空串
//注意經過removeAttribute,不能刪除value
alert(inputs.getAttribute("value"));//abc
inputs.removeAttribute("value");
alert(inputs.getAttribute("value"));//abc
</script>