喵喵时光机
一个非常丑陋但以某种方式起作用的示例指定了textarea行然后在js中 $("textarea").on('keydown keypress keyup',function(e){ if(e.keyCode == 8 || e.keyCode == 46){return true; } var maxRowCount = $(this).attr("rows") || 2; var lineCount = $(this).val().split('\n').length; if(e.keyCode == 13){if(lineCount == maxRowCount){ return false;} } var jsElement = $(this)[0]; if(jsElement.clientHeight < jsElement.scrollHeight){var text = $(this).val();text= text.slice(0, -1);$(this).val(text);return false; } });