gpt4 book ai didi

javascript - jQuery 包含在 Chrome 上不起作用

转载 作者:数据小太阳 更新时间:2023-10-29 04:26:12 25 4
gpt4 key购买 nike

我有一个关于 jquery contains 的问题。它在 Firefox 上运行完美。

这是我的代码。

$("input[data-height='cm']").blur(function(){
var text = $(this).val();

if($(this).val().length > 0) {
if(!$(this).val().contains("cm")) {
$(this).val(text + " cm");
}
}
});

在 chrome 上它给出错误

Uncaught TypeError: $(...).val(...).contains is not a function

我该如何解决,请帮忙。

谢谢。

最佳答案

使用 indexOf 而不是 contains

 if($(this).val().indexOf("cm") == -1) {
$(this).val(text + " cm");
}

关于javascript - jQuery 包含在 Chrome 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30190710/

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