1

以下のマークアップに関する 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 ブラウザーで正常に動作します。しかし、.9 や .1 のように 1 未満の 10 進数を入力すると、onblur が検証され、入力フィールドがクリアされます。

入力が任意の数字と小数を受け入れることを期待しています...

コードサンプルの実行はこちら

4

1 に答える 1

1

古い投稿ですが、私もこれに遭遇しました。

それを回避するために私が行ったことは、「。」をキャッチすることです。キーダウンで (キーアップは Android では正常に機能しましたが、IOS では問題が発生しました)、 の前に値を 0 に設定します。適用されます。ただし、少なくとも 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-12-18T23:10:55.797 に答える