javascript获取html标签的实例

<DOCTYPE HTML PUBLIC "-//W3C//DTD// HTML 4.0 Transitional//EN">
<!--function里面的每一行alert分别取消注释,然后单击按钮可以看到效果-->
<html>
<head>
<meta http-equiv="content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
	function getwebsite(){
		//alert(id_reg1.href);
		//alert(document.all.name_reg1.href);
		//alert(document.all(8).href);
		//alert(document.anchors(1).href);
		//alert(document.getElementById("id_reg1").href);
		//alert(document.getElementsByName("name_reg1")[0].href);
		//alert(document.getElementsByTagName("a")[2].href);
		//alert(document.all.tags("a")[2].href);//获取第三个a标签
	}
	
</script>
</head>
<body>
<a id="id_reg1" name="name_reg1" href="点我1.html">点我1</a>
<a id="id_reg2" name="name_reg2" href="点我2.html">点我2</a>
<a href="点我3.html">点我3</a>
<a href="点我4.html">点我4</a>
<input type="button" οnclick="getwebsite()" value="获取网址">
</body>
</html>
发布了23 篇原创文章 · 获赞 4 · 访问量 11万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章