新的 Jquery 当复选框被选中时,我正在向 div 控件插入文本。我想在取消选中“复选框”时删除该文本
<div align="center" id="chkBoxes">
<asp:CheckBox ID="chbIceCream" text ="Ice Cream" runat="server"></asp:CheckBox>
<asp:CheckBox ID="chbCake" Text ="Cake" ClientIDMode="static" runat="server" />
<asp:CheckBox ID="chbChocolet" Text ="Cho colet" runat="server" />
</div>
<div id="ContentDiv">
</div>
jQuery代码:
$(document).ready(function () {
$('#chbIceCream').click(function () {
var Text = $("input:checkbox[id$=chbIceCream]").next().text();
if ($(this).attr('checked'))
$('#ContentDiv').append(Text);
else
$('#ContentDiv').remove(Text);
});
});