nextSibling下一个兄弟节点
previousSibling上一个兄弟
parentNode父亲节点
1 <select><option value="zs">中山</option><option value="gz">广州</option><option value="zh">深圳</option><option value="zh">珠海</option></select> 2 <script type="text/javascript"> 3 //取得<select>元素节点下的子元素的个数 4 //var selectElement = document.getElementsByTagName("select")[0]; 5 //var size = selectElement.childNodes.length; 6 //alert("select下共有"+size+"个元素"); 7 8 //取得“中山”字符串 9 //var selectElement = document.getElementsByTagName("select")[0]; 10 //var zsElement = selectElement.firstChild; 11 //var zs = zsElement.innerHTML; 12 //alert(zs); 13 14 //取得"广州"字符串 15 //var selectElement = document.getElementsByTagName("select")[0]; 16 //var zsElement = selectElement.firstChild; 17 //var gzElement = zsElement.nextSibling; 18 //var gz = gzElement.innerHTML; 19 //alert(gz); 20 21 //取得"珠海"字符串 22 //var selectElement = document.getElementsByTagName("select")[0]; 23 //var zhElement = selectElement.lastChild; 24 //var zh = zhElement.innerHTML; 25 //alert(zh); 26 27 //取得"深圳"字符串 28 //var selectElement = document.getElementsByTagName("select")[0]; 29 //var zhElement = selectElement.lastChild; 30 //var szElement = zhElement.previousSibling; 31 //var sz = szElement.innerHTML; 32 //alert(sz); 33 34 //删除"广州"元素 35 var gzElement = document.getElementsByTagName("option")[1]; 36 var selectElement = gzElement.parentNode; 37 selectElement.removeChild(gzElement); 38 39 40 41 42 </script>
js firstChild 、nextSibling、lastChild、previousSibling、parentNode,布布扣,bubuko.com
js firstChild 、nextSibling、lastChild、previousSibling、parentNode