您好,这是我文件头中的内容:
function entsub(event)
{
if (event && event.which == 13)
write1();
else
return true;
}
在体内,我的形式是:
<form id="writeform" name="writeform">
Message: <br />
<textarea name="message" rows="3" id="message" style="width:90%;" onkeypress="return entsub(event)"></textarea>
<br />
<input name="send" type="button" id="send" value="Send" onclick="write1()" />
<span id="sent"></span>
<input type="reset" value="Reset" />
</form>
我需要确保在文本区域中按回车键时,它不会换行,而是发送新行[请参见我的
<input type="button">
]但这是行不通的!它一直在换行...现在使用IE8。
最佳答案
使用keyCode代替。
根据浏览器,您需要阻止默认操作。检查IE的event.cancelBubble和event.returnValue以及Firefox的event.stopPropagation()和event.preventDefault()。