猿问

哪错了??求教

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>显示和隐藏</title>

<script>

var oP1=document.getElementById("p1");

function myhidden()

{

oP1.style.visibility="hidden";

};

function myvisible()

{

oP1.style.visibility="visible";

};

</script>

</head>


<body>

<p id="p1">This is a text!</p>

<input type="button" value="hidden" onclick="myhidden()"/>

<input type="button" value="visible" onclick="myvisible()" />

</body>


Ewall_
浏览 1603回答 1
1回答

初恋茶香

var oP1=document.getElementById("p1");这里应该写在input后面,这样在加载页面时,运行到var oP1=document.getElementById("p1");才获取的到id为p1这个对象
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答