DOM对象操作HTML元素和消息对话框(alert,confirm,prompt)
<head>
<meta charset="UTF-8">
<title>DOM对象操作HTML元素和消息对话框</title>
</head>
<body>
<p name="pn">hello</p>
<p name="pn">hello</p>
<p name="pn">hello</p>
<p name="pn">hello</p>
<a id="aid" title="你点击了我">hello world</a>
<ul>
<li>第一个</li>
<li>第二个</li>
<li>第三个</li>
<li>第四个</li>
</ul>
<ul>
<li>第一个</li>
<li>第二个</li>
<li>第三个</li>
<li>第四个</li>
</ul>
<script>
function getByName(){
var pname=document.getElementsByName("pn");
alert(pname.length);
var pnode=pname[2];
pnode.innerHTML=window.prompt("提示","请输入你的姓名");
var yesorno=window.confirm("单击“确定”继续。单击“取消”停止。");
if(yesorno){
alert("欢迎你访问我们的web主页");
}
else{
alert("你看到这么华丽的界面,你舍得退出吗");
}
}
function getByTagName(){
var ptagname=document.getElementsByTagName("p");
alert(ptagname.length);
var pnode=ptagname[1];
pnode.innerHTML=window.prompt("提示","请输入内容");
}
function getAttribute(){
var anode=document.getElementById("aid");
var attr=anode.getAttribute("title");
alert(attr);
}
function setAttribute(){
var anode=document.getElementById("aid");
var attr=anode.setAttribute("title","动态修改了title属性内容");
var attr=anode.getAttribute("title");
alert(attr);
}
function getChildNode(){
var childnode=document.getElementsByTagName("ul")[0].childNodes;
alert(childnode.length);
}
//getByName();
//getByTagName();
//getAttribute();
//setAttribute();
getChildNode();
</script>
</body>