<html>
<head>
<title>回车键提交演示</title>
<style type="text/css">
<!--
.STYLE3 {
font-size: 24px;
color: #FF0000;
}
hr {
width:60%;
color: #FF0078;
text-align:left;
}
-->
</style>
<script type="text/javascript">
function init()
{
document.onkeypress =send;
}
function send(){
//如果按了回车键也发送信息
if(event.keyCode==13&&event.type=="keypress"&&event.srcElement
.id!="content") {//键盘按下Enter键
sendMessage();
}
}
function sendMessage()
{
alert("send success!");
}
</script>
</head>
<body onLoad="init()">
<span class="STYLE3">回车键提交演示</span>
<hr>
功能:在输入区域回车,只换行不提交;但在其他区域回车即提交。
<hr>
<div>
请输入内容: <br><textarea rows="10" id="content" ></textarea> <br>
<input type="button" value="发送" οnclick="sendMessage()"/>
</div>
</body>
</html>