如何用js实现点击radiobutton 显示隐藏层
4个回答
展开全部
<script>
function hideDiv()
{
//以下两个语句,用visibility即使隐藏也占渲染位置,用display相当于将这个div彻底抹掉
document.getElementById("div1").style.visibility = "hidden";
document.getElementById("div2").style.display = "none";
}
</script>
<input type="radio" onclick="hideDiv()" />点我
<div id="div1" style="visibility:visible;">123</div>
<div id="div2" style="display:block;">456</div>
上面是让初始显示的层隐藏掉,反过来做就是
<script>
function hideDiv()
{
document.getElementById("div1").style.visibility = "visible";
document.getElementById("div2").style.display = "block";
}
</script>
<input type="radio" onclick="hideDiv()" />点我
<div id="div1" style="visibility:hidden">123</div>
<div id="div2" style="display:none">457</div>
function hideDiv()
{
//以下两个语句,用visibility即使隐藏也占渲染位置,用display相当于将这个div彻底抹掉
document.getElementById("div1").style.visibility = "hidden";
document.getElementById("div2").style.display = "none";
}
</script>
<input type="radio" onclick="hideDiv()" />点我
<div id="div1" style="visibility:visible;">123</div>
<div id="div2" style="display:block;">456</div>
上面是让初始显示的层隐藏掉,反过来做就是
<script>
function hideDiv()
{
document.getElementById("div1").style.visibility = "visible";
document.getElementById("div2").style.display = "block";
}
</script>
<input type="radio" onclick="hideDiv()" />点我
<div id="div1" style="visibility:hidden">123</div>
<div id="div2" style="display:none">457</div>
展开全部
<form id="form1" name="form1" method="post" action="">
<label>
<input type="radio" name="radiobutton" value="radiobutton" onclick="document.getElementById('test').style.visibility='visible'"/>男
</label>
</form>
<div id="test" style="visibility:hidden; width:200px; height:20px">这是隐藏层</div>
<label>
<input type="radio" name="radiobutton" value="radiobutton" onclick="document.getElementById('test').style.visibility='visible'"/>男
</label>
</form>
<div id="test" style="visibility:hidden; width:200px; height:20px">这是隐藏层</div>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
主页 1.html
<html>
<body>
<script type="text/javascript">
function SetPPP(s) {
document.getElementById("ppp").value = s;
}
</script>
<input type="text" id="ppp" />
<button onclick="SetPPP('a')">主页a</button>
<iframe src="2.html"></iframe>
</body>
附页 2.html
<html>
<body>
<input type="radio" value="b" onclick="parent.SetPPP(this.value)" />B<br />
<input type="radio" value="C" onclick="parent.SetPPP(this.value)" />C<br />
</body>
</html>
一般在页面中我们定义js函数myfunction(),调用它实际上是window.myfunction(),调用父窗口的js函数用parent.myfunction()
<html>
<body>
<script type="text/javascript">
function SetPPP(s) {
document.getElementById("ppp").value = s;
}
</script>
<input type="text" id="ppp" />
<button onclick="SetPPP('a')">主页a</button>
<iframe src="2.html"></iframe>
</body>
附页 2.html
<html>
<body>
<input type="radio" value="b" onclick="parent.SetPPP(this.value)" />B<br />
<input type="radio" value="C" onclick="parent.SetPPP(this.value)" />C<br />
</body>
</html>
一般在页面中我们定义js函数myfunction(),调用它实际上是window.myfunction(),调用父窗口的js函数用parent.myfunction()
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
增加onclick属性就可以了啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询