我有以下代码:
$(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/