在Button按键中运行另一个对象的Event Function?! [英] Run another object Event Function in Button keypress ?!
本文介绍了在Button按键中运行另一个对象的Event Function?!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我有一个使用php的聊天应用程序!
当您在texteria中写您的消息并单击Enter时,发送消息....
它与MVC和Ajax和...!当您单击Enter时,我无法通过Function Run找到它.
我可以在附近设置一个按钮并在onclick中运行文本框按键功能吗?
像这样的东西? :
< button></button>
Hi
I have an chat application with php !
and when u write your message in texteria and click on Enter it send message ....
its with mvc and ajax an ... ! I cant find with Function Run when u click on Enter !
Can I set a Button near that and Run the textbox keypress function in onclick ?
somthing like this ?? :
<button ></button>
推荐答案
您需要检查代表Enter键的键码13.
Hi,
You need to check for keycode 13 which stands for Enter key.
<html>
<head>
<script>
function process(e)
{
var code = (e.keyCode ? e.keyCode : e.which);
if(code == 13) { //Enter keycode
alert("Sending your Message : " + document.getElementById('txt').value);
}
}
</script>
</head>
<body>
<textarea id="txt" cols="40" rows="5" onkeypress="process(event, this)">
</textarea>
</body>
</html>
Thx
Thx
只是为了支持 srikantsahu 所说的内容,一个简单的 Demo ...
[演示]检测对TextArea的Enter键 [
Just to support what srikantsahu said, a simple Demo...
[Demo] Detect Enter Key Press on TextArea[^]
这篇关于在Button按键中运行另一个对象的Event Function?!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文