= 0){ -6ren">
gpt4 book ai didi

javascript - 在 jquery 循环中为选项设置文本时出错

转载 作者:行者123 更新时间:2023-12-01 03:35:47 25 4
gpt4 key购买 nike

我有以下代码:

 $('#selectid option').each(function(){
if( this.text.indexOf("abcxyz") >= 0){
var lable = this.text.replace("abcxyz", "");
this.text(lable);
}
});

我不明白为什么会出现此错误:

this.text is not a function

我的代码有什么问题吗?请帮我解决这个问题。

谢谢大家。

最佳答案

尝试使用 $(this) 而不是 this:

$('#selectid option').each(function(){
if( $(this).text().indexOf("abcxyz") >= 0){
var lable = $(this).text().replace("abcxyz", "");
$(this).text(lable);
}
});

关于javascript - 在 jquery 循环中为选项设置文本时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44297876/

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