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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章