Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.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 检测滚动条何时出现在texarea上_Javascript_Jquery - Fatal编程技术网

Javascript 检测滚动条何时出现在texarea上

Javascript 检测滚动条何时出现在texarea上,javascript,jquery,Javascript,Jquery,我知道有人问过这个问题。该解决方案基本上是可行的,但他们使用的是旧版本的jquery,并且该解决方案是使用不推荐使用的函数实现的。因此,根据本文的答案和问题,我尝试迁移到新版本 因此,基本上,使用旧jquery版本的解决方案就是这个 $('textarea.paginate').live('keydown', function(event) { if (this.clientHeight < this.scrollHeight) { alert("Please So

我知道有人问过这个问题。该解决方案基本上是可行的,但他们使用的是旧版本的jquery,并且该解决方案是使用不推荐使用的函数实现的。因此,根据本文的答案和问题,我尝试迁移到新版本

因此,基本上,使用旧jquery版本的解决方案就是这个

$('textarea.paginate').live('keydown', function(event) {
    if (this.clientHeight < this.scrollHeight) {
        alert("Please Something);
    }
});
$('textarea.paginate').live('keydown',函数(事件){
if(this.clientHeight
这是我向on函数的迁移,但两种方法都不起作用。示例演示:

我做错了什么

$("textarea").on('keyup','.note-codable',function(event){
  if(event.keyCode == 13) { }
  if (this.clientHeight < this.scrollHeight) {
    alert("Please Something");
  }
});

$(document).on('keyup','.note-codable',function(event){
  if(event.keyCode == 13) { }
  if (this.clientHeight < this.scrollHeight) {
    alert("Please Something");
  }
});
$(“textarea”).on('keyup','note codable',函数(事件){
如果(event.keyCode==13){}
if(this.clientHeight
已更新

尝试这种方法:

$.fn.hasVerticalScrollBar = function() {
    if (this[0].clientHeight < this[0].scrollHeight) {
        return true
    } else {
        return false
    }
};

$(document).on('keydown','.note-codable',function(event){
    if(event.keyCode == 13) { }
    if ($(this).hasVerticalScrollBar()) {
        alert("Please Something");
    }
});
$.fn.hasVerticalScrollBar=函数(){
if(此[0].clientHeight<此[0].scrollHeight){
返回真值
}否则{
返回错误
}
};
$(文档).on('keydown','note codable',函数(事件){
如果(event.keyCode==13){}
if($(this).hasVerticalScrollBar()){
警惕(“请做某事”);
}
});
另外,如果您注意到我已将
keyup
事件更改为
keydown
,我认为这会更好,因为当用户将手指按在按钮上时,如果在
keyup
事件上,则不会触发代码。

修复了您的问题

在第一种方法中,您只需在
live
处使用
.on

$('textarea.paginate').on('keydown', function(event) {

    // scrollbars apreared
    if (this.clientHeight < this.scrollHeight) {

       alert("Please add a new card for having a better format. Remember this is a WYSIWYG");

    }

});
$('textarea.paginate')。打开('keydown',函数(事件){
//滚动条
if(this.clientHeight