在学习JavaScript的时候,重要的知识是对HTML的操作,这些知识统称为DOM
一获得HTML的标签的方法
1、document.getElementById('标签的id值') //通过标签的id属性来找到标签。
eg:
<html>
<head>
<script type="JavaScript">
function fun1()
{
var dic= document,.getElementById('div');
}
</script>
</head>
<body>
<div id="div"></div>
</body>
</html>
2、document.getElementTagName('标签') //通过标签的名称来找到标签。
eg;
<html>
<head>
<script type="Javascript">
function fun1()
{
var li=doucment.getElementTagName('li');//在这里获取是li的集合。就意味着这里li是数组
}
</script>
</head>
<body>
<div>
<ul>
<li></li>
<li></li>
</ul>
</div>
</body>
</html>
3.、document.getElementName(‘具有name属性的相同属性值')//通过name属性来找到标签
<html>
<head>
<script type="Javascript">
function fun1()
{
var radio=document.getElementName('name');//这时获取的同样是个集合
}
</script>
</head>
<body>
<div>
<input type="radio" name="name" value="男"/>
<input type="radio" name="name" value="女'/>
</div>
</body>
</html>