我知道有人问过这个问题 here 。基本上,该解决方案有效,但他们使用的是旧版本的 jquery,并且该解决方案是使用已弃用的函数实现的。所以我尝试根据此question中的答案和问题迁移到新版本。 .
所以基本上使用旧 jquery 版本的解决方案就是这个。
$('textarea.paginate').live('keydown', function(event) {
if (this.clientHeight < this.scrollHeight) {
alert("Please Something);
}
});
这是我向 on 函数的迁移,但两种方法都不起作用。示例演示:http://jsbin.com/saxay/1/edit
我做错了什么?
$("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");
}
});
最佳答案
解决了你的问题
您只需在第一种方法中的 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");
}
});
关于javascript - 检测文本区域上何时出现滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25278709/