如何在 jQuery 中使用模糊?



我有以下代码:

$(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不起作用。如何在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");
}
});
});

最新更新