onclick复选框,隐藏div并显示另一个div

时间:2011-08-28 23:51:41

标签: jquery

我实际上没有为此做过任何代码,在互联网上搜索并找到了这篇文章:

http://iamzed.com/jquery/showhidediv.html

为了我们的目的而思考......

我们正在制作的表格的一部分,正常显示。是这样的:

enter image description here

选中复选框,隐藏上面的div并显示此div ..

enter image description here

3 个答案:

答案 0 :(得分:2)

我试图模仿我在图片中看到的内容in fiddle.它没有样式,但它具有您正在寻找的功能。

答案 1 :(得分:1)

假设你有正确的html结构,你要隐藏的所有东西都在id为yourOldContent的div中,你想要显示的是id为yourDivWithNewContent的div(最初用display:none;隐藏),并且复选框有id checkboxId,您可以使用以下代码:

 $('#checkboxId').click(function(){
  $('#yourDivWithNewContent').toggle();
  $('yourOldContent').toggle();
});

答案 2 :(得分:1)

$("#checkbox").click(function(){
   if ($(this).is(':checked')){
      $("#box1").show();
      $("#button_feature").show();
      $("#button_normal").hide();
   }
   else{
      $("#box1").hide();
      $("#button_feature").hide();
      $("#button_normal").show();
   }
});