示例:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>display</title>
<script type="text/javascript">
function hidetext()
{
var mychar = document.getElementById("con");
mychar.style.display = "none"; (注意一定要加引号)
}
function showtext()
{
var mychar = document.getElementById("con");
mychar.style.display = "block"; (注意一定要加引号)
}
</script>
</head>
<body>
<h1>JavaScript</h1>
<p id="con">内容</p>
<form>
<input type="button" onclick="hidetext()" value="隐藏内容" />
<input type="button" onclick="showtext()" value="显示内容" />
</form>
</body>
</html>
结果: