Capture “done” button click in iphone's virtual keyboard with Javascript

元气小坏坏 提交于 2019-11-28 06:45:43

The done key is the same as the enter key. So you can listen to a keypress event. I'm writing this using jQuery and i use it in coffee script so I'm trying to convert it back to js in my head. Sorry if there is an error.

$('someElem').bind("keypress", function(e){
   // enter key code is 13
   if(e.which === 13){
     console.log("user pressed done");
    } 
})

I was unable to track the 'done' button being clicked. It didn't register any clicks or keypresses. I had to addEventListeners for change, focusout and blur using jquery (because the project already was using jquery).

You need to do some kind of this:

$('someElem').focusout(function(e) {
    alert("Done key Pressed!!!!")
});

It worked for me, hope it will help you as well.

After searching and trying this solution basically is say:

 document.addEventListener('focusout', e => {});

tested on IPhone 6s

The answer by oron tech using an event listener is the only one that works cross platform.

 document.getElementById("myID").addEventListener("focusout", blurFunction);

 function blurFunction() { // Do whatever you want, such as run another function
const myValue = document.getElementById("myID").value;
myOtherfunction(myValue);
}

attach a blur event to the text box in question. The done fire will fire this event.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!