<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>
1 回答
初恋茶香
TA贡献2条经验 获得超0个赞
var oP1=document.getElementById("p1");
这里应该写在input后面,这样在加载页面时,运行到var oP1=document.getElementById("p1");才获取的到id为p1这个对象
添加回答
举报
0/150
提交
取消