<SCRIPT LANGUAGE="JavaScript">
function keyup(eventobject)
{
if(event.ctrlKey && window.event.keyCode==13 )
{
document.post.submit();
document.post.Submit.disabled=true;
}
}
</SCRIPT> <textarea name="text" cols="78" rows="8" onkeyup="keyup()"></textarea>
function keyup(eventobject)
{
if(event.ctrlKey && window.event.keyCode==13 )
{
document.post.submit();
document.post.Submit.disabled=true;
}
}
</SCRIPT> <textarea name="text" cols="78" rows="8" onkeyup="keyup()"></textarea>
判断事件对象的键值,一个是不是ctrlKey(Control键),keyCode==13回车。
如果是的话,表单递交到服务器。submit();
function keyup(eventobject)
{
if(event.ctrlKey && window.event.keyCode==13 )
{
document.post.submit();
document.post.Submit.disabled=true;
}
}
</SCRIPT> <textarea name="text" cols="78" rows="8" onkeyup="keyup()"></textarea>
我的程序是
private void Publish_Click(object sender, System.EventArgs e)
{
DBAccess Access = new DBAccess(strConn);
Account myAccount = new Account(mid,strDomain); string strCommand;
string TID = TB_TID.Text.Trim();//Thread ID
string MFID = FaceList.Items[FaceList.SelectedIndex].Value; // Message Face ID
string FID = TB_ClassID.Text; // Forum ID
string msgID = commClass.generateID("Msg"); // Massge ID
string strTitle = TB_Title.Text.Trim();
string strContent = TB_Content.Text.Trim();
string NickName = myAccount.NickName;
string PubDate = DateTime.Now.ToString();
string Status = "0";
strCommand = "update Comm_ForumThread set PubDate = '"+ PubDate +"',ReplyNum = ReplyNum + 1 where ID = '"+ TID +"'";
strCommand += "insert into Comm_ForumMessage(ID,MFID,TID,MID,NickName,Title,Content,PubDate,Status) values('"+ msgID +"','"+ MFID +"','"+ TID +"','"+ mid +"','"+ NickName +"','"+ strTitle +"','"+ strContent +"','"+ PubDate +"','"+ Status +"')";
if (strTitle != "")
{
try
{
Access.ExeSqlCommand(strCommand);
}
catch(CustomException ce)
{
Response.Redirect("/bbs/Error.aspx?msg=" + ce.GetStrExtendErrMsg(),true);
}
catch(Exception)
{
Response.Redirect("/bbs/Error.aspx?msg=意外错误!",true);
} this.SavePicture(msgID); // 上传图片 Response.Redirect("/bbs/ShowThread.aspx?ID=" + TID,true);
}
else
{
Response.Redirect("/bbs/Error.aspx?msg=主题不能为空!",true);
} }
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
function test()
{
if(window.event.keyCode==13&&window.event.ctrlKey)
{
document.haha.submit();
}
}
</script>
</HEAD>
<BODY>
<body onkeydown="test();">
<form action="lyok.asp" name="haha" method="post" >
<textarea rows="4" name="cword" cols="49"></textarea>
<input type="submit" value="提交" >
</form>
</body>
</BODY>
</HTML>
private void bt1_Click(object sender, System.EventArgs e)
{
Response.Write("你同时按下了ctrl和enter");
}调用
<script language="javascript">
function document.onkeydown()
{
if((window.event.keyCode == 13) && (window.event.ctrlKey))
{
document.forms(0).bt1.click();
}
}
</script>
<INPUT onfocus="aa()" onblur="ss()" id="s1" runat=server name="s1" type="text">
private void bt1_Click(object sender, System.EventArgs e)
{
Response.Write("你同时按下了ctrl和enter");
}<script language="javascript">
var b = null;
function aa()
{
b='ss';
}
function ss()
{
b=null;
}
function document.onkeydown()
{
if(b != null)
{
if((window.event.keyCode == 13) && (window.event.ctrlKey))
{
document.forms(0).bt1.click();
} }
}
</script>
第一次无论输入框获得焦点与否,都执行ctrl+enter事件
第二次更正,当输入框获得焦点,执行ctrl+enter事件