gpt4 book ai didi

javascript - jquery 字符串变量上的每个函数

转载 作者:行者123 更新时间:2023-11-30 06:39:51 25 4
gpt4 key购买 nike

我用 javascript 编写了一个函数,它采用 <tr> 的标题属性调用 ajax 然后在一些操作之后它从它们中检索一些标题属性。根据该标题属性,我想删除那些 <tr>行数

function currentTicketStatus() {
var ids = '';
$('tbody tr[title]').each(function() {
ids += ((ids == '') ? '' : ',') + $(this).attr('title');
});
$.ajax({
url: 'ajaxExecute.aspx?Fn=CTS',
type: 'POST',
context: document.body,
cache: false,
data: 'Tickets=' + ids,
success: function(response) {
if (response != '') {
if (response.substr(0, 5) != 'ERROR') {
var sTickets = response.split('|');

sTickets.each(function() {
$(this).parent().parent().remove();
});
}
}
}
});
}

示例:在ajax调用时ids="100,101,102,103,104"在ajax调用之后sTickets="101|102" .现在删除那些具有 sTickets 属性的行

HTML(不完全是)

<tbody>
<tr title="100"> some data part </tr>
<tr title="101"> some data part </tr>
<tr title="102"> some data part </tr>
<tr title="103"> some data part </tr>
</tbody>

最佳答案

thiseach是一个“标题”(字符串),您需要 DOM 元素(<tr>)代替

sTickets.each(function() {
$('tbody tr[title="'+ this +'"]').remove();
});

demo

关于javascript - jquery 字符串变量上的每个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12244261/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com