当用户按 Enter 键时,我一直在尝试更改 textarea 的高度,这样他们就不必滚动了。我可以在 IE 和 Chrome 上管理它,但我无法让它在 Firefox 上运行。请看一下我的代码。我对此真的很陌生。似乎它无法识别事件,我想不出办法。这是我的代码:
<form id="blog-comment-form" method="post" action="index.php">
<textarea id="comment" name="b_com" onkeyup="showmsg()" placeholder="ADD YOUR COMMENT HERE"></textarea>
<input type="submit" name="submit" value="POST COMMENT"/>
</form>
我正在从外部文件调用该函数。还有我的javascript代码:
function showmsg() {
if(!event){
event= window.event;}
if (event.keyCode==13) {
var a = document.getElementById("comment");
var b = document.getElementById("comment").style.scrollHeight;
a.style.height = ((a.scrollHeight)+6) + "px";
}else {
var a = document.getElementById("comment");
var b = document.getElementById("testthis").style.height;
a.style.height = ((a.scrollHeight)+6) + "px";
}
}
谢谢你