gpt4 book ai didi

javascript - 如何在 jQuery 中使用模糊?

转载 作者:行者123 更新时间:2023-12-03 03:39:16 24 4
gpt4 key购买 nike

我有以下代码:

 $(function() {
$('.type_choice_textarea').on('focus', function() {
$(this).css("height", "150px");
});
if ($('.type_choice_textarea').val().length == 0) {
$('.type_choice_textarea').on('blur', function() {
$(this).css("height", "30px");
});
}
});

但是模糊不起作用。如何在 blur 中使用 if

最佳答案

只需在模糊事件处理程序中编写 if 条件即可

 $(function() {
let elem = '.type_choice_textarea';

$(elem).on('focus', function() {
$(this).css("height", "150px");
});

$(elem).on('blur', function() {
if ($(this).val().length == 0) {
$(this).css("height", "30px");
}
});
});

关于javascript - 如何在 jQuery 中使用模糊?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45705662/

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