[英]How to stop focusout(blur) on submit? For Phonegap
I am trying to stop the focusout(blur)
event when i click submit for a textinput
. 我试图阻止
focusout(blur)
事件,当我点击提交了textinput
。
I just dont want the textinput
to lose focus and stop closing the soft keyboard. 我只是不想让
textinput
失去焦点并停止关闭软键盘。
I tried doing this below to avoid the focusout
, but that prevents me closing the keyboard all together when i need to. 我尝试在下面进行此操作以避免
focusout
,但这使我在需要时完全关闭键盘。 Any Idea? 任何想法?
textarea.addEventListener("blur", function() {
setTimeout(function() {
textarea.focus();
}, 0);
});
Edit var mousedownHappened = false; 编辑var mousedownHappened = false;
$('input').blur(function() {
if(mousedownHappened) // cancel the blur event
{
alert('stay focused!');
$('input').focus();
mousedownHappened = false;
}
else // blur event is okay
{
// Do stuff...
}
});
$('a').mousedown(function() {
mousedownHappened = true;
});
html: 的HTML:
<input type="text" id="test" name="test" />
<input type="submit" value="focus" id="submit"/>
js: js:
document.getElementById('submit').addEventListener("click",function(e){
e.preventDefault();
document.getElementById('test').focus();
});
If you are using Phonegap use this solution. 如果您正在使用Phonegap,请使用此解决方案。
$('input').blur(function() {
if(mousedownHappened) // cancel the blur event
{
alert('stay focused!');
$('input').focus();
mousedownHappened = false;
}
else // blur event is okay
{
// Do stuff...
}
});
$('a').mousedown(function() {
mousedownHappened = true;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.