我有使用以下html删除多个块的问题。我能够通过使用下面的jquery删除单个块。但我不知道如何删除多个块。要删除多个块我有复选框,但它没有工作。我正在粘贴下面的单个删除jquery代码。任何人都可以帮助我,如何删除多个块。我已粘贴下面的html
当我点击删除时,会删除一个块。我粘贴在下面的代码。
$("#addSentiment").on("click", ".dialogs .itemdiv .tools span", function(e){
$(this).closest('.dialogs .itemdiv').remove();
});
为了删除多个块,我有一个像这样的外部复选框。当我点击外部复选框时,我正在使用以下Jquery代码来检查所有复选框。基本上不能使用jquery删除多个项目
使用复选框(jquery)选择多个块的代码
$('#selecctall').click(function(event) { //on click
if(this.checked) { // check select status
$('.checkbox1').each(function() { //loop through each checkbox
this.checked = true; //select all checkboxes with class "checkbox1"
});
}else{
$('.checkbox1').each(function() { //loop through each checkbox
this.checked = false; //deselect all checkboxes with class "checkbox1"
});
}
});
<div class="panel-heading">
<h3 class="panel-title">
<input type="checkbox" id="selecctall">Multiple List
<span class="delrt"><a id="del">Delete</a></span>
</h3>
</div>
<div id="addSentiment" class="dialogs"><div id="1" class="dialogs">
<div class="itemdiv dialogdiv">
<div class="body">
<div class="name">
<input type="checkbox" value="4502216" name="check[]" class="checkbox1"> <a href="#">qwe@xxxx.com</a>
</div>
<div id="cat_1" class="text"><b>Category</b> : as<br></div>
<div id="op_1" class="text"><b>Opissnion worssd/phrase</b> : One<br></div>
<div id="feature_1" class="text"><b>Feassture wossrd/psshrase</b> : formal<br></div>
<div id="score_1" class="text"><b>Score</b> : Positive<br></div>
<div class="text"><input type="hidden" value="1" name="hd"></div>
<div class="docidhd"><input type="hidden" value="4502216" name="hddocid" id="hddocid_1"><input type="hidden" value="1" name="cntupdt" id="cntupdt"></div>
<div class="tools">
<a id="edit_1" class="btn acebtn btn-minier btn-info" href="#">
<i class="icon-only ace-icon fa fa-share"></i>
</a>
<span class="dlt">
<a id="delete_1" class="btn acebtn btn-minier btn-info dlt" href="#">
<i class="icon-only ace-icon fa fa-share"></i>
delete
</a>
</span>
</div>
</div>
</div></div><div id="2" class="dialogs">
<div class="itemdiv dialogdiv">
<div class="body">
<div class="name">
<input type="checkbox" value="4502217" name="check[]" class="checkbox1"> <a href="#">email@email.com</a>
</div>
<div id="cat_2" class="text"><b>Category</b> : Acsssaascess<br></div>
<div id="op_2" class="text"><b>Opinssion word/phrase</b> : testing opinssion<br></div>
<div id="feature_2" class="text"><b>Feassture word/phrase</b> : Thumsssbs up<br></div>
<div id="score_2" class="text"><b>Scssore</b> : possstive<br></div>
<div class="text"><input type="hidden" value="2" name="hd"></div>
<div class="docidhd"><input type="hidden" value="4502217" name="hddocid" id="hddocid_2"></div>
<div class="tools">
<a id="edit_2" class="btn acebtn btn-minier btn-info" href="#">
<i class="icon-only ace-icon fa fa-share"></i>
</a>
<span class="dlt">
<a id="delete_2" class="btn acebtn btn-minier btn-info dlt" href="#">
<i class="icon-only ace-icon fa fa-share"></i> delete</a>
</span>
</div>
</div>
</div>
</div>
</div>
我只粘贴了2个街区。我可能会获得无限制的区块
答案 0 :(得分:2)
$(".panel-heading").on("click", "#del", function(e) {
$('.dialogs').find("input[name='check[]']:checked").closest('.dialogs').remove();
});
答案 1 :(得分:0)
要在jquery选择器字符串中获取多个项目,请使用逗号,
:
$(this).closest('.dialogs, .itemdiv').remove();