<!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>display</title>
<script type="text/javascript">
function hidetext()
{
var mychar=document.getElementById("con").style.display="none";
}
function showtext()
{
var mychar=document.getElementById("con")
mychar=style.display="block";
}
</script>
</head>
<body>
<p id="con">这是我的第一个dom练习代码</p>
<form>
<input type="button" onclick="hidetext" value="不显示段落内容" />
<input type="button" onclick="showtext" value="显示内容" />
</form>
</body>
</html>
为什么不能隐藏和显示啊? 问题出在哪里?
<!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>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> <p id="con">这是我的第一个dom练习代码</p> <form> <input type="button" onclick="hidetext()" value="不显示段落内容" /> <input type="button" onclick="showtext()" value="显示内容" /> </form> </body> </html>
调用出问题,而且showtext函数也没写对