在HTML中,通过Button控制DIV的显示与隐藏
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript">
var flag=0;
function $(id)
{
return document.getElementById(id);
}
function controlDIV()
{
if(flag==0)
{
$("my").style.visibility="hidden";
$("bt_display").value="显示";
flag=1;
}
else
{
$("my").style.visibility="";
$("bt_display").value="隐藏";
flag=0;
}
}
</script>
</head>
<body>
<input type="button" id="bt_display" value="隐藏" onclick="controlDIV()"/>
<div id="my">
<input type="text" value="my DIV"/>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript">
var flag=0;
function $(id)
{
return document.getElementById(id);
}
function controlDIV()
{
if(flag==0)
{
$("my").style.visibility="hidden";
$("bt_display").value="显示";
flag=1;
}
else
{
$("my").style.visibility="";
$("bt_display").value="隐藏";
flag=0;
}
}
</script>
</head>
<body>
<input type="button" id="bt_display" value="隐藏" onclick="controlDIV()"/>
<div id="my">
<input type="text" value="my DIV"/>
</div>
</body>
</html>
posted on 2011-03-23 13:21 CANYOUNG 阅读(10542) 评论(0) 编辑 收藏 举报