我可以做到这一点,只需在for循环中执行,但我需要在不使用循环的情况下执行。
有可能吗?下面是我写的一些代码:
function submitFormArchive(Status) {
var siteUrl = $("#pageurl").val();
$("#archive-loader").show();
var myCheckboxes = new Array();
$("input[type='checkbox'][name='archive[]']:checked").each(function () {
myCheckboxes.push($(this).val());});
alert(myCheckboxes);///this one i am getting dynamic ids
$.ajax({
type: 'POST',
url: siteUrl + 'Appadmins/ajaxUpdateArchive',
data: {"myCheckboxes": myCheckboxes, "status": Status},
success: function (data) {
$("#remove-id-"+myCheckboxes).slice(myCheckboxes).remove();
}
});
return false;
}
<tr class="message_box" id='remove-id-<?php echo $list->id;?>'></tr>
This one in for loop
I am posting some part of codes.
$("#remove-id-" + myCheckboxes).slice(myCheckboxes).remove();
是否有多个,也许我在上面的代码中写错了。
试试下面的代码
$("input[type='checkbox'][name='archive[]']:checked").each(function() {
myCheckboxes.push($(this).val());
});
alert(myCheckboxes); //40,39,38 //it can be any id ,as i made it dynamic .
// construct array of IDs here
var ids = myCheckboxes.map(function(id) { return "#remove-id-" + id; });
// ["#remove-id-40", "#remove-id-39", "#remove-id-38"]
// concat all id selectors together using comma `,`
var idSelector = ids.join(",");
// "#remove-id-40,#remove-id-39,#remove-id-38"
// remove all at once.
$(idSelector).remove();
$("input[type='checkbox'][name='archive[]']:checked").each(function() {
$("#remove-id-" + $(this).val()).remove();
});