如何从停止按钮时preSS进入被解雇 [英] how to stop a button from being fired when press enter
本文介绍了如何从停止按钮时preSS进入被解雇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用这个功能来处理输入点击一个搜索文本框,但它触发页面另一个按钮,如何从被解雇的停止按钮,并叫我search()函数。
InputKey preSS(五){
如果(window.event){
如果(event.key code == 13){
搜索();
}
}其他{
如果(E){
如果(e.which == 13){
搜索();
}
}
}
}
解决方案
您需要添加返回false是这样的:
功能InputKey preSS(五){
如果(E!)
E = window.event;
VAR键code = e.key code || e.which;
如果(键code == 13){
搜索();
返回false;
} 返回true;
}
,改变从文本框调用此:
<输入....安其preSS =返回InputKey preSS(事件); ...>
含义不只是调用函数而已,回归了。
I am using this function to handle enter click on a search textbox but it fires another button in the page, how to stop that button from being fired and call my search() function.
InputKeyPress(e) {
if (window.event) {
if (event.keyCode == 13) {
search();
}
} else {
if (e) {
if (e.which == 13) {
search();
}
}
}
}
解决方案
You need to add "return false" like this:
function InputKeyPress(e) {
if (!e)
e = window.event;
var keyCode = e.keyCode || e.which;
if (keyCode == 13) {
search();
return false;
}
return true;
}
And also change the call from the textbox to this:
<input .... onkeypress="return InputKeyPress(event);" ...>
Meaning not just call the function but "return" it.
这篇关于如何从停止按钮时preSS进入被解雇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文