如何在 jQuery 中使用模糊?
How do I use blur in 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
?
如果条件在模糊事件处理程序中,请写信给你
$(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");
}
});
});
我有以下代码:
$(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
?
如果条件在模糊事件处理程序中,请写信给你
$(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");
}
});
});