我使用JQuery。我需要隐藏表格的列(基于div)。在下面的示例中,我需要在单击复选框时隐藏/显示文本框。隐藏文本框后,第2段将移至上方。同样,我不需要改变客户名称的位置。地址。
HTML代码
<input type="checkbox" id="chk" />Check it, if customer has no company.
<span>Paragraph 1st Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum </span>
<div class="divTable">
<div class="headRow">
<div class="divCell" align="center">Company Name</div>
<div class="divCell">Customer Name</div>
<div class="divCell">Customer Address</div>
</div>
<div class="divRow">
<div class="divCell" align="center"><input type="text" /></div>
<div class="divCell" align="center">Customer Name</div>
<div class="divCell" align="center">Customer Address</div>
</div>
<div class="divRow">
<div class="divCell" align="center"><input type="text" /></div>
</div>
<div class="divRow">
<div class="divCell" align="center"><input type="text" /></div>
</div>
</div>
<p>Paragraph 2nd Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum </P>
CSS是,
.divTable
{
display: table;
width:auto;
background-color:#eee;
border:1px solid #666666;
border-spacing:5px;
}
.divRow
{
display:table-row;
width:auto;
}
.divCell
{
float:left;
display:table-column;
width:200px;
background-color:#ccc;
}
如何隐藏表格列(基于div)?
答案 0 :(得分:1)
这可行:
$("input[type=checkbox]").on("change", function(){
$("input[type=text]").toggle();
});
答案 1 :(得分:0)
尝试
$('input[type=text]').css('visibility','hidden');
而不是像这样隐藏它们
$('#chk').click(function(){
if($('input[type=text]').css('visibility')=='hidden')
{
$('input[type=text]').css('visibility','');
}
else
{
$('input[type=text]').css('visibility','hidden')
}
});
答案 2 :(得分:0)
你想要这样的Demo
$("input[type=checkbox]").on("change", function(){
$(".divTable").toggle();
});