<input value="我是用id来获取值的" type="button" onclick="GetById()"/>
<input value="我是用Name来获取值的" type="button" onclick="GetByName()"/>
<input value="我是用tagName来获取值的" type="button" onclick="GetByTagName()"/>
<div id="divid" name="divName">我是用来测试的div</div>
<script type="text/javascript">
function GetById() {
var a = document.getElementById("divid");
alert(a.nodeName + "," + a.nodeType + "," + a.nodeValue);
var text = a.innerHTML;
alert(text);
//1、给字体设置颜色
// a.innerHTML = "现在已经改了".fontcolor("red");
//2、给div设置样式
a.style.width="500px";
a.style.height="300px";
a.style.border="1px solid red";
}
function GetByName() {
var b = document.getElementsByName("divName");
alert(b.nodeName);
alert(b[0].nodeName + "-" + b[0].nodeType + "-" + b[0].nodeValue);
}
function GetByTagName() {
var c = document.getElementsByTagName("div");
alert(c.nodeName);
alert(c[0].nodeName + "-" + c[0].nodeType + "-" + c[0].nodeValue);
}
</script>