访问HTML标签的属性1

<html>
<head>
<title>访问HTML标签的属性</title>
<script language="JavaScript">
function setAlign(strAlign){
   myP.align = strAlign;
}
function getAlign(){
   alert(document.all.tags("P").item(0).align);
}
function switchAlign(){
   var objEle = document.all.tags("P");
   if (objEle(1).getAttribute("align")=="left")
      objEle(1).setAttribute("align", "center");
   else
      objEle(1).setAttribute("align", "left");
}
</script>
</head>
<body id="myBody">
<h2>访问HTML标签的属性</h2>
<hr>
<p id="myP" align="left">访问HTML标签的属性1</p>
<p align="left">访问HTML标签的属性2</p>
<form>
<input type="button" onclick="setAlign('center')" value="置中对齐">
<input type="button" onclick="getAlign()" value="获取标签属性">
<input type="button" onclick="switchAlign()" value="切换标签属性">
</form>
</body>
</html>


 

posted on 2010-04-21 15:10  wtq  阅读(256)  评论(0编辑  收藏  举报