Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在jQuery中使用模糊?_Javascript_Jquery_Focus_Blur - Fatal编程技术网

Javascript 如何在jQuery中使用模糊?

Javascript 如何在jQuery中使用模糊?,javascript,jquery,focus,blur,Javascript,Jquery,Focus,Blur,我有以下代码: $(function() { $('.type_choice_textarea').on('focus', function() { $(this).css("height", "150px"); }); if ($('.type_choice_textarea').val().length == 0) { $('.type_choice_textarea').on('blur', function() {

我有以下代码:

 $(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");
      }
    });
});

if
条件移动到
blur
事件处理程序中。i、 e.
$('.type_choice_textarea').on('blur',function(){if($(this.val().length==0){$(this.css(“height”,“30px”);})您的代码可以很好地用于me@CarstenLøvboAndersen,取决于您希望它做什么:)«如何使用模糊中的if?»。。。好吧,用它吧!