不废话。直接上代码。
$("#commentContent").val("").keyup(function (event) {
// ctrl + enter 提交评论
if (event.keyCode === 13 && event.ctrlKey) {
Comment.add(Label.articleOId);
}
// 根据换行符设置 rows
this.rows = this.value.split("\n").length;
// 当一行长度超过时自动折行,无换行符的处理
// Chrome 中需计算 padding 上下高度 this.scrollHeight - paddingTop - paddingBottom > $(this).height()
while (this.scrollHeight > $(this).height()) {
this.rows += 1;
}
// 底部需留空一行,美观大方
this.rows += 1;
});