问题
We are developing a regular asp.net website (no Textviews), for one of the text boxes I need the textbox to open a numeric keyboard by default, is there a way to achieve this?
Below code works perfectly for iPhone / iPad but does not default to numeric keyboard for Android.
<asp:TextBox runat="server" type="number" pattern="\d*" onKeypress="if(event.keyCode < 48 || event.keyCode > 57){return false;}" />
Adroid version : 2.2.1
EDIT : When I use an HTML input box with type="number" it works perfectly. I need a way to use asp.Net textbox and see the numeric keyboard.
回答1:
Here is my solution:
<div style="display:none"><asp:TextBox ID="txt_Phone" runat="server" /></div>
<input onblur="document.getElementById('<%=txt_Phone.ClientID %>').value = this.value" type="tel" />
Enjoy :)
回答2:
Here's a slightly more elegant way:
PhoneBox.Attributes.Add("type", "tel");
This way there is only one input control and it doesn't mess up client-side validation. Also it makes it easy to assign this attribute to multiple controls (I just added a "keypad" class to the controls that I want it to apply to, then use a recursive control search method to find them all and add the attribute).
来源:https://stackoverflow.com/questions/6765990/asp-net-textbox-in-android-phone-with-numeric-keyboard-selected-by-default