gpt4 book ai didi

javascript - 如果输入包含至少一个字符

转载 作者:行者123 更新时间:2023-11-29 11:01:46 25 4
gpt4 key购买 nike

抱歉,我问的问题早已得到解答。但是我找不到我需要的答案。

问题是我想检查输入值。如果 unfocus 后输入有一个或多个文本(做某事)

 var inputLength = $('input').val();
if (inputLength.length > 1) {
$('span.input--madoka').addClass('myclass')
}
else {

}

最佳答案

使用 blur() 当元素失去焦点时调用你的函数的事件

这是例子

$('#filter').blur(function() {

var inputLength = $(this).val();

if (inputLength.length > 1) {

console.log('has something');

// here you add whatever class you want to add to other element

} else {

console.log('has nothing');

// here some other action
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="filter" value="" />

关于javascript - 如果输入包含至少一个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45796707/

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