按键事件没有在Android手机中启动

时间:2021-10-24 15:19:09

I am using backbone,marionette for my Application.I used same code for both desktop and mobile but keypress not working in mobile.I made a Jsfiddle for testing.

我正在使用主干,marionette作为我的应用。我在桌面和移动设备上都使用了相同的代码,但是按键在移动设备上不能工作。我做了一个测试用的Jsfiddle。

If you open this link in mobile event not firing,If you open in desktop it's firing.How can I resolve this.

如果你在移动事件中打开这个链接而不是启动,如果你在桌面中打开它就会启动。我如何解决这个问题。

can anyone help me.

谁能帮助我。

Thanks.

谢谢。

4 个解决方案

#1


8  

Chrome mobile doesn't support keypress events properly for now. There is a long standing bug for this:

Chrome移动目前不支持按键事件。有一个长期存在的缺陷:

https://code.google.com/p/chromium/issues/detail?id=118639

https://code.google.com/p/chromium/issues/detail?id=118639

I believe it should be fixed in v38.

我认为应该在v38中修正。

#2


5  

I will suggest two events on input box.

我将在输入框中建议两个事件。

This will work on desktop webbrowser.

这将在桌面web浏览器上工作。

1) onkeypress = return isNumberKey(event);

1) onkeypress = return isNumberKey(event);

function isNumberKey(e)
{
    var evt = e || window.event;

    if(evt) 
    { 
        var charCode = evt.keyCode || evt.which; 
    }
    else 
    { 
        return true; 
    }

    if((charCode > 47 &&  charCode < 58) || charCode == 9 || charCode == 8 || charCode ==46 || charCode ==37 || charCode==39)
    { 
        return true; 
    }

    return false;
}

This will work for mobile

这将适用于移动设备

2) onkeyup="numberMobile(event);"

2)onkeyup = " numberMobile(事件);“

function numberMobile(e){
    e.target.value = e.target.value.replace(/[^\d]/g,'');
    return false;
}

Apply both event on the input box and it will work.Only drawback is,It make it slow.But for now we have to live with it.

在输入框上应用这两个事件,它将会工作。唯一的缺点是,它会使速度变慢。但现在,我们必须接受它。

There is one issue woth this solution.Left navigation is not working.I will update more appropriate solution soon.

这个解决方案有一个问题。左导航不工作。我将很快更新更合适的解决方案。

#3


1  

Tested on browserstack. Seems to be working to me. Here's a link to your gist:

browserstack上测试过。对我来说似乎很有效。以下是你的要点:

http://www.browserstack.com/start#os=android&os_version=4.1&device=Samsung+Galaxy+S+III&zoom_to_fit=true&full_screen=true&url=http%3A%2F%2Fjsfiddle.net%2F33Snz%2F3%2Fembedded%2Fresult%2F&speed=1&start=true

http://www.browserstack.com/start os = android&os_version = 4.1星系及器具=三星+ + S + III&zoom_to_fit = true&full_screen = true&url 3 = http % % 2 f % 2 fjsfiddle.net % 2 f33snz % 2 f3 % 2 fembedded % 2 fresult % 2 f&speed = 1开始= true

Can you let know what specific andriod device and browser you testing in.

你能告诉我你测试的是什么特定的andriod设备和浏览器吗?

#4


1  

Finally I found a problem,but it won't work in opera.Instead of writing the code for numeric fields.I just added an attribute type='number' to input field in html file.Now only numeric keypad is coming.So it satisfies my requirements.Here is the JsFiddle

最后我发现了一个问题,但在歌剧中行不通。而不是为数字字段编写代码。我刚刚在html文件中为输入字段添加了一个属性类型='number'。现在只有数字键盘出现了。所以它满足我的要求。这是JsFiddle

html code:

html代码:

<input type='number'/>

#1


8  

Chrome mobile doesn't support keypress events properly for now. There is a long standing bug for this:

Chrome移动目前不支持按键事件。有一个长期存在的缺陷:

https://code.google.com/p/chromium/issues/detail?id=118639

https://code.google.com/p/chromium/issues/detail?id=118639

I believe it should be fixed in v38.

我认为应该在v38中修正。

#2


5  

I will suggest two events on input box.

我将在输入框中建议两个事件。

This will work on desktop webbrowser.

这将在桌面web浏览器上工作。

1) onkeypress = return isNumberKey(event);

1) onkeypress = return isNumberKey(event);

function isNumberKey(e)
{
    var evt = e || window.event;

    if(evt) 
    { 
        var charCode = evt.keyCode || evt.which; 
    }
    else 
    { 
        return true; 
    }

    if((charCode > 47 &&  charCode < 58) || charCode == 9 || charCode == 8 || charCode ==46 || charCode ==37 || charCode==39)
    { 
        return true; 
    }

    return false;
}

This will work for mobile

这将适用于移动设备

2) onkeyup="numberMobile(event);"

2)onkeyup = " numberMobile(事件);“

function numberMobile(e){
    e.target.value = e.target.value.replace(/[^\d]/g,'');
    return false;
}

Apply both event on the input box and it will work.Only drawback is,It make it slow.But for now we have to live with it.

在输入框上应用这两个事件,它将会工作。唯一的缺点是,它会使速度变慢。但现在,我们必须接受它。

There is one issue woth this solution.Left navigation is not working.I will update more appropriate solution soon.

这个解决方案有一个问题。左导航不工作。我将很快更新更合适的解决方案。

#3


1  

Tested on browserstack. Seems to be working to me. Here's a link to your gist:

browserstack上测试过。对我来说似乎很有效。以下是你的要点:

http://www.browserstack.com/start#os=android&os_version=4.1&device=Samsung+Galaxy+S+III&zoom_to_fit=true&full_screen=true&url=http%3A%2F%2Fjsfiddle.net%2F33Snz%2F3%2Fembedded%2Fresult%2F&speed=1&start=true

http://www.browserstack.com/start os = android&os_version = 4.1星系及器具=三星+ + S + III&zoom_to_fit = true&full_screen = true&url 3 = http % % 2 f % 2 fjsfiddle.net % 2 f33snz % 2 f3 % 2 fembedded % 2 fresult % 2 f&speed = 1开始= true

Can you let know what specific andriod device and browser you testing in.

你能告诉我你测试的是什么特定的andriod设备和浏览器吗?

#4


1  

Finally I found a problem,but it won't work in opera.Instead of writing the code for numeric fields.I just added an attribute type='number' to input field in html file.Now only numeric keypad is coming.So it satisfies my requirements.Here is the JsFiddle

最后我发现了一个问题,但在歌剧中行不通。而不是为数字字段编写代码。我刚刚在html文件中为输入字段添加了一个属性类型='number'。现在只有数字键盘出现了。所以它满足我的要求。这是JsFiddle

html code:

html代码:

<input type='number'/>