gpt4 book ai didi

jquery - 查找 id 不包含某些字符的所有文本框

转载 作者:行者123 更新时间:2023-12-01 00:00:49 27 4
gpt4 key购买 nike

我有以下代码,我正在尝试检索 id 不包含单词 OT 的文本框。

<input type="text" id="txtMo1">
<input type="text" id="txtOTMo1">
<input type="text" id="txtTu1">
<input type="text" id="txtOTTu1">
...
...
<input type="text" id="txtMo4">
<input type="text" id="txtOTMo4">
<input type="text" id="txtTu4">
<input type="text" id="txtOTTu4">
...
...

我尝试使用.find,其中idtxt开头,但它给了我一切(显然)。如何仅检索 id 以 txt 开头但不包含 OT 的文本框?

.find("input[id ^= 'txt']")

最佳答案

不要使用选择器:使用过滤器:

.find('input[id^="txt"]').filter(function() {
return -1 === this.id.indexOf('OT');
});

如果应保留元素,则对 filter 的回调应返回 true;如果应删除元素,则应返回 false。在这种情况下,该函数将返回 true,并且如果 indexOf 返回 -1,则该元素将被保留,这意味着 OT 不存在。

关于jquery - 查找 id 不包含某些字符的所有文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9213551/

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