Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.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 在onkeyup事件中未检测到Textarea更改?_Javascript_Jquery_Html - Fatal编程技术网

Javascript 在onkeyup事件中未检测到Textarea更改?

Javascript 在onkeyup事件中未检测到Textarea更改?,javascript,jquery,html,Javascript,Jquery,Html,加载页面时,需要在KeyUp事件上检测Textarea更改。Textarea的大小调整工作正常,但加载页面时,在KeyUp事件中未检测到Textarea。我尝试了以下代码 <script> jQuery.each(jQuery('textarea[data-autoresize]'), function () { var offset = this.offsetHeight - this.clientHeight; var resizeText

加载页面时,需要在KeyUp事件上检测Textarea更改。Textarea的大小调整工作正常,但加载页面时,在KeyUp事件中未检测到Textarea。我尝试了以下代码

<script>
    jQuery.each(jQuery('textarea[data-autoresize]'), function () {
        var offset = this.offsetHeight - this.clientHeight;
        var resizeTextarea = function (el) {
            jQuery(el).css('height', 'auto').css('height', el.scrollHeight + offset);
        };
        jQuery(this).on('keyup input', function () {
            resizeTextarea(this);
        });
        jQuery(this).trigger('keyup');
    });
</script>

每个函数(){
var offset=this.offsetHeight-this.clientHeight;
var resizeTextarea=函数(el){
jQuery(el).css('height','auto').css('height',el.scrollHeight+offset);
};
jQuery(this).on('keyup input',function(){
重新调整区域(此区域);
});
jQuery(this.trigger('keyup');
});

一旦单据加载完毕,您就应该执行jquery

像这样包装:

<script>
$(document).ready(function(){
      jQuery.each(jQuery('textarea[data-autoresize]'), function () {
        var offset = this.offsetHeight - this.clientHeight;
        var resizeTextarea = function (el) {
            jQuery(el).css('height', 'auto').css('height', el.scrollHeight + offset);
        };
        jQuery(this).on('keyup input', function () {
            resizeTextarea(this);
        });
        jQuery(this).trigger('keyup');
    });
});
</script>

$(文档).ready(函数(){
每个函数(){
var offset=this.offsetHeight-this.clientHeight;
var resizeTextarea=函数(el){
jQuery(el).css('height','auto').css('height',el.scrollHeight+offset);
};
jQuery(this).on('keyup input',function(){
重新调整区域(此区域);
});
jQuery(this.trigger('keyup');
});
});

一旦单据加载完毕,您就应该执行jquery

像这样包装:

<script>
$(document).ready(function(){
      jQuery.each(jQuery('textarea[data-autoresize]'), function () {
        var offset = this.offsetHeight - this.clientHeight;
        var resizeTextarea = function (el) {
            jQuery(el).css('height', 'auto').css('height', el.scrollHeight + offset);
        };
        jQuery(this).on('keyup input', function () {
            resizeTextarea(this);
        });
        jQuery(this).trigger('keyup');
    });
});
</script>

$(文档).ready(函数(){
每个函数(){
var offset=this.offsetHeight-this.clientHeight;
var resizeTextarea=函数(el){
jQuery(el).css('height','auto').css('height',el.scrollHeight+offset);
};
jQuery(this).on('keyup input',function(){
重新调整区域(此区域);
});
jQuery(this.trigger('keyup');
});
});

尝试在
窗口中运行代码。onload

window.onload=function(){
    jQuery.each(jQuery('textarea[data-autoresize]'), function() {
      var offset = this.offsetHeight - this.clientHeight;
      var resizeTextarea = function(el) {
        jQuery(el).css('height', 'auto').css('height', el.scrollHeight + offset);
      };
      jQuery(this).on('keyup input', function() {
        resizeTextarea(this);
      });
      jQuery(this).trigger('keyup');
    });

    //trigger when modal showing
    $('.modal').on('shown.bs.modal', function () { 
        jQuery('textarea[data-autoresize]').trigger('keyup');
    })

}

拨弄在
窗口中运行代码。onload

window.onload=function(){
    jQuery.each(jQuery('textarea[data-autoresize]'), function() {
      var offset = this.offsetHeight - this.clientHeight;
      var resizeTextarea = function(el) {
        jQuery(el).css('height', 'auto').css('height', el.scrollHeight + offset);
      };
      jQuery(this).on('keyup input', function() {
        resizeTextarea(this);
      });
      jQuery(this).trigger('keyup');
    });

    //trigger when modal showing
    $('.modal').on('shown.bs.modal', function () { 
        jQuery('textarea[data-autoresize]').trigger('keyup');
    })

}

fiddle

我们可以用HTML做一个工作演示吗?你把你的
放在哪里了?我们可以用HTML做一个演示吗?您的
放在哪里了?请发布您的htmlPlease发布您的htmlin Add子句弹出窗口?在这种情况下,您需要触发模态显示,例如$('.modal').on('show.bs.modal',function(){jQuery('textarea[data autoresize]')).trigger('keyup');})你能给我举个例子吗?我认为这不应该发生在jQuery(this).on('keyup input',function(){resizeTextarea(this);}).trigger('keyup');您还可以尝试如何在代码中设置触发键控事件的超时?在Add子句弹出窗口中?确定在这种情况下,您需要在模式显示时触发,例如$('.modal').on('show.bs.modal',function(){jQuery('textarea[data autoresize]')).trigger('keyup');})你能给我举个例子吗?我认为这不应该发生在jQuery(this).on('keyup input',function(){resizeTextarea(this);}).trigger('keyup');您还可以尝试如何在代码中设置触发器键控事件的超时?