<p name="pn">hello</p>
<p name="pn">hello</p>
<p name="pn">hello</p>
<script>
function getName(){
var count=document.getElementsByName("pn");
alert(count.length);
var p=count[2];
p.innerHTML="world";
}
</script>
<p>hello</p>
<p>hello</p>
<p>hello</p>
<script>
function getName(){
var count=document.getElementsByTagName("p");
alert(count.length);
var p=count[2];
p.innerHTML="world";
}
</script>
<a id="aid" title="得到a的标签属性"></a>
<script>
function getAttr1(){
var anode=document.getElementById("aid");
var attr=anode.getAttribute("id");
alert("a的ID是:"+attr);
}
function getAttr2(){
var anode=document.getElementById("aid");
var attr=anode.getAttribute("title");
alert("a的title内容是:"+attr);
}
getAttr1();
getAttr2();
</script>
<a id="aid2">aid2</a>
<script>
function setAttr(){
var anode=document.getElementById("aid2");
anode.setAttribute("title","动态设置a的title属性");
var attr=anode.getAttribute("title");
alert("动态设置的title值为:"+attr);
}
setAttr();
</script>
<ul><li>1</li><li>2</li><li>3</li></ul>
<script>
function getChildNode(){
var childnode=document.getElementsByTagName("ul")[0].childNodes;
alert(childnode.length);
alert(childnode[0].nodeType);
}
getChildNode();
</script>
<div>
<p id="pid"></p>
</div>
<script>
function getParentNode(){
var div=document.getElementById("pid");
alert(div.parentNode.nodeName);
}
getParentNode();
</script>
<script>
function createNode(){
var body=document.body;
var input=document.createElement("input");
input.type="button";
input.value="按钮";
body.appendChild(input);//插入节点
}
createNode();
</script>
<script>
function createNode(){
var element = document.createElement("div");
element.className = "message";
var textNode = document.createTextNode("Hello world!");
element.appendChild(textNode);
document.body.appendChild(element);
}
createNode();
</script>
<div id="div">
<p id="pid">p元素</p>
</div>
<script>
function addNode(){
var div=document.getElementById("div");
var node=document.getElementById("pid");
var newnode=document.createElement("p");
newnode.innerHTML="动态插入一个p元素";
div.insertBefore(newnode,node);
}
addNode();
</script>
<div id="div">
<p id="pid">p元素</p>
</div>
<script>
function removeNode(){
var div=document.getElementById("div");
var p=div.removeChild(div.childNodes[1]);
}
removeNode();
</script>
<script>
function getSize(){
var width=document.documentElement.offsetWidth||document.body.offsetWidth;//解决兼容问题
var height=document.documentElement.offsetHeight||document.body.offsetHeight;
alert(width+","+height);
}
getSize();
</script>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有