所有HTML元素都拥有的属性:id,title,lang,dir,className。 DOM集合:
JavaScript获取元素的三种方法:
<!DOCTYPE html>
<html>
<head>
<style>
.box{
width:500;
height:500;
}
</style>
<script>
function f1(){
var d1 = document.getElementById('d1');
var d2 = document.getElementByTagName('div');
var d3 = document.getElementByClassName('box');
}
</script>
</head>
<body onload = "f1()" >
<div id="d1" class="box">
<p>这只是一个例子</p>
</div>
</body>
</html>
节点属性:
<!DOCTYPE html>
<html>
<head>
<script>
function f1(){
var node = document.getElementById('d1');
alert(node.nodeName);
}
</script>
</head>
<body onload = "f1()" >
<div id="d1">
<p>这只是一个例子</p>
</div>
</body>
</html>
关于节点操作的方法:
<!DOCTYPE html>
<html>
<head>
<script>
function f1(){ //给div追加一个段落
var div = document.getElementById('d1');
var newP = document.craeteElement('p');
var textNode = document.createTextNode('This is an demo.');
newP.appendChild(textNode);
div.appendChild(newP);
}
</script>
</head>
<body onload = "f1()" >
<div id="d1">
<p>这只是一个例子</p>
</div>
</body>
</html>
关于属性操作的方法:
|

ecshop仿益生康保健品商城
人气:946
ecshop大气蔬果商城
人气:585
Magento时尚餐厅主题模板
人气:268
ecshop仿OPPO手机商城整站程
人气:1226
ecshop英文外贸高尔夫模板
人气:715
Luxury高端时尚magento主题模
人气:116