gpt4 book ai didi

jquery - 获取 jQuery .filter() 结果的相反/相反结果

转载 作者:行者123 更新时间:2023-12-01 06:22:11 24 4
gpt4 key购买 nike

我有一个.filter函数,它起作用并标记 <td> 的所有 parent 包含一个红色的输入字段。

但是,我需要完全相反的东西。因此返回所有不包含 <input 的字段。我试过if ($(this).html().indexOf('<input') == -1) {但这只是以某种方式标记所有行。

我的 jQuery:

$(document).ready(function () {
$("#ListView1_itemPlaceholderContainer table table table td").filter(function (index) {
if ($(this).html().indexOf('<input') > 0) {
return true;
}
}).closest('div').css('background-color', 'red');
});

这是我的 HTML

 <div id="ListView1_itemPlaceholderContainer" style=
"font-family: Verdana, Arial, Helvetica, sans-serif;">
<div style="background-color: #FFFFFF; color: #333333;">
<table style="width: 100%;">
<tbody>
<tr>
<td style="width: 71px"><img id="ListView1_userInfo1_0_ImageUser_0" src=
"http://pbs.twimg.com/profile_images/13/6GA5kEu6_normal.png" style=
"height:65px;width:65px;" /></td>

<td style="vertical-align: top">
<table style="width: 100%;">
<tbody>
<tr>
<td></td>
</tr>

<tr>
<td>
<table style="width: 100%;">
<tbody>
<tr>
<td><img id="ListView1_userInfo1_0_Imagebg_0" src=
"https://pbs.twimg.com/profile_banners/13/1402427948" style=
"height:64px;width:251px;" /><br />
<span id="ListView1_userInfo1_0_LabelName_0">dfgdfg</span>
&nbsp; @<span id=
"ListView1_userInfo1_0_LabelUserName_0">dfgdfg</span></td>

<td style="text-align: right"></td>
</tr>
</tbody>
</table>
</td>
</tr>

<tr>
<td><span style="font-size:10px">Follower-<span id=
"ListView1_userInfo1_0_LabelFollower_0">4578</span> &nbsp; ,
Following-<span id=
"ListView1_userInfo1_0_LabelFollowing_0">1654</span></span></td>
</tr>

<tr>
<td><span id="ListView1_userInfo1_0_LabelAbout_0"></span></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table><br />
</div>

<div style="background-color: #EEEEEE;color: #333333;">
<table style="width: 100%;">
<tbody>
<tr>
<td style="width: 71px"><img id="ListView1_userInfo_1_ImageUser_1" src=
"http://pbs.twimg.com/profile_images/12/ECWtACTn_normal.jpeg" style=
"height:65px;width:65px;" /></td>

<td style="vertical-align: top">
<table style="width: 100%;">
<tbody>
<tr>
<td></td>
</tr>

<tr>
<td>
<table style="width: 100%;">
<tbody>
<tr>
<td><img id="ListView1_userInfo_1_Imagebg_1" src=
"http://pbs.twimg.com/profile_background_images/37/pTBlAXSm.jpeg"
style="height:64px;width:251px;" /><br />
<span id="ListView1_userInfo_1_LabelName_1">dfgdfgd</span>
&nbsp; @<span id=
"ListView1_userInfo_1_LabelUserName_1">dfgdfgdf</span></td>

<td style="text-align: right"><input type="submit" name=
"ListView1$ctrl1$userInfo$ButtonFollow" value="Follow" id=
"ListView1_userInfo_1_ButtonFollow_1" style=
"height:100px;width:100px;" /></td>
</tr>
</tbody>
</table>
</td>
</tr>

<tr>
<td><span style="font-size:10px">Follower-<span id=
"ListView1_userInfo_1_LabelFollower_1">4622</span> &nbsp; ,
Following-<span id=
"ListView1_userInfo_1_LabelFollowing_1">4007</span></span></td>
</tr>

<tr>
<td><span id="ListView1_userInfo_1_LabelAbout_1"></span></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table><br />
</div>
</div>

我还查看了这篇文章jQuery: use filter(), but work with both results正如评论者所建议的。

并尝试了这个:

<script type="text/javascript">

$(document).ready(function () {
$.fn.invert = function () {
return this.end().not(this);
};

$("#ListView1_itemPlaceholderContainer table table table td").filter(function (index) {
if ($(this).html().indexOf('<input') > 0) {
return true;
}
}).invert().closest('div').css('background-color', 'red');
});

</script>

但这也会使所有行变成红色。

最佳答案

您可以使用.not()以及:has()

$(document).ready(function () {
$("#ListView1_itemPlaceholderContainer table table table td").not(':has(input)').closest('div').css('background-color', 'red');
});

关于jquery - 获取 jQuery .filter() 结果的相反/相反结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27308761/

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