javascript中隐藏和显示对象时失效,如下小程序
如下程序在隐藏功能失效,望解决,谢谢<html><head><title>HidingandShowingObjects</title><scriptlanguage="...
如下程序在隐藏功能失效,望解决,谢谢
<html>
<head>
<title>Hiding and Showing Objects</title>
<script language="JavaScript" type="text/javascript">
function ShowHide(){
if(!document.getElementById()){
return
}
var head1 = document.getElementById("head1");
var head2 = document.getElementById("head2");
var showhead1 = document.form1.head1.checked;
var showhead2 = document.form1.head2.checked;
head1.style.visibility=(showhead1)?"visible":"hidden";
head2.style.visibility=(showhead2)?"visible":"hidden";
}
</script>
</head>
<body>
<h1 ID="head1">This is the first heading</h1>
<h1 ID="head2">This is the second heading</h1>
<p>
Using the W3C DOM,you can choose whether to show or hide the headings on
this page using the checkboxes below.
</p>
<form name="form1">
<input type="checkbox" name="head1" checked onClick="ShowHide();">
<b>Show first heading</b><br>
<input type="checkbox" name="head2" checked onClick="ShowHide();">
<b>Show second heading</b><br>
</form>
</body>
</html> 展开
<html>
<head>
<title>Hiding and Showing Objects</title>
<script language="JavaScript" type="text/javascript">
function ShowHide(){
if(!document.getElementById()){
return
}
var head1 = document.getElementById("head1");
var head2 = document.getElementById("head2");
var showhead1 = document.form1.head1.checked;
var showhead2 = document.form1.head2.checked;
head1.style.visibility=(showhead1)?"visible":"hidden";
head2.style.visibility=(showhead2)?"visible":"hidden";
}
</script>
</head>
<body>
<h1 ID="head1">This is the first heading</h1>
<h1 ID="head2">This is the second heading</h1>
<p>
Using the W3C DOM,you can choose whether to show or hide the headings on
this page using the checkboxes below.
</p>
<form name="form1">
<input type="checkbox" name="head1" checked onClick="ShowHide();">
<b>Show first heading</b><br>
<input type="checkbox" name="head2" checked onClick="ShowHide();">
<b>Show second heading</b><br>
</form>
</body>
</html> 展开
2个回答
展开全部
if(!document.getElementById())
里面没有值,所以没有执行 去掉 就可以了
里面没有值,所以没有执行 去掉 就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询