【问题标题】:Android browser input type numberAndroid浏览器输入类型号
【发布时间】:2013-02-02 18:51:17
【问题描述】:

Android 浏览器 (4.03) 中出现以下标记问题。

<html> 
<body> 
Androind 4.03 Browser test page<br />
Type .9 in the input field below and click/tap button below.<br />
Browser validation is clearing contents in input field.<br /></br/>


<input type="number" pattern="[0-9\.]*" step="0.1" min="0.0"></input> <br /><br /><br />

<input type="button" value="Validate" />

</body>
</html>

我希望数字小键盘能在焦点上显示出来,它适用于 iphone 和 android 2.x 浏览器。 但是,当我输入小于 1 的小数(如 .9 或 .1)时,它会验证 onblur 并清除输入字段。

我希望输入可以接受任何数字和小数...

Run code sample here

【问题讨论】:

    标签: javascript android html android-browser


    【解决方案1】:

    旧帖子,但我也遇到过这个问题。

    我为解决这个问题所做的工作是捕捉 '.'在 keydown 上(keyup 在 android 上运行良好,但在 IOS 上导致问题),并在 .被申请;被应用。 然而,我注意到,至少在 android 浏览器上,这会干扰之后完全擦除数字的能力(如果你要退格),所以我也必须抓住它。

    // within a keydown handler for the input, 
    // where "this" is the input, and "e" is the event
    
    // make it 0 before the . gets applied
    if((e.keyCode == 190 || e.keyCode = 46)
        && (!this.value || this.value == '.'))
    {
        this.value = 0;
        return;
    }
    
    // ...but that screws up the cursor position on
    // some browsers, so handle the backspace 
    if(e.keyCode == 8 && this.value == '0.')
    {
        this.value = '';
        return;
    }
    

    感觉很老套,但似乎有效。

    【讨论】:

      猜你喜欢
      • 2013-02-04
      • 1970-01-01
      • 1970-01-01
      • 2011-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-13
      • 2012-06-21
      相关资源
      最近更新 更多