注意:不能用document.getElementsByName;会出现对象未被引用。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function toggle(targetid,objN){
var target=document.getElementById(targetid);
var aa=document.getElementById(objN)
if (target.style.display=="block"){
target.style.display="none";
aa.innerText="显示";
} else {
target.style.display="block";
aa.innerText='隐藏';
}
}
-->
</script>
<style type="text/css">
<!--
#div1{
background-color:#000000;
height:400px;
400px;
display:none;
}
#div2{
background-color:#000000;
display:block;
}
-->
</style>
</head>
<body>
<input type="button" id="butn" value="显示" onClick="toggle('div1','butn')" />
<a href="#" id="aa" onClick="toggle('div1','aa')">显示</a>
<form name="frm1">
<center>
<div id="div1">
<input type="text" name="txt" width="18">
</div></center>
居中的DIV
</form>
</body>
</html>