Iphone开发 - 如何显示数字键盘?

时间:2011-07-19 20:22:49

标签: iphone keyboard numeric

我正在开发一个不是原生iPhone应用程序的移动网站,而是一个简单的m.somedomain.com网站,该网站是用c#asp.net开发的。

目标: 单击其中一个文本框时,如何仅显示数字键盘?

注意:该网站不是HTML5,不是Native应用内的Webview的一部分,而是一个独立的常规网站

我的文本框是一个常规的asp.net文本框:

<asp:TextBox runat="server" CssClass="reference_input" Text="1234567"  />

3 个答案:

答案 0 :(得分:13)

编辑:我发现您可以使用here

<input type="text" pattern="[0-9]*" />

告诉移动safari将数字键盘设置为默认值,无需指定电话键盘。

编辑2 (来自以下评论):您还可以使用javascript强制数字输入:

<input type="text" pattern="[0-9]*" onKeypress="if(event.keyCode < 48 || event.keyCode > 57){return false;}" />

答案 1 :(得分:4)

如果你使用type =“tel”而不是type =“text”,它会弹出一个数字键盘。

答案 2 :(得分:0)

对于Salesforce(不是HTML输入类型='数字'),下面的java脚本应该会使iPad,iPhone数字键盘默认出现。 (此解决方案也适用于asp.net控件)

    <apex:page standardController="Account" >
    <head>
     <script type="text/javascript"> 
      function addLoadEvent(func)  
      { 
       var oldonload = window.onload; 
       if (typeof window.onload != 'function') 
       { 
         window.onload = func; 
       } 
       else 
       { 
         window.onload = function()  
        { 
          if (oldonload) 
           { 
             oldonload(); 
           } 
           func(); 
        } 
       } 
      }     

      addLoadEvent(function() 
      { 
       try{
          var ctl = document.getElementById('{!$Component.frm.txtNumeric}'); 
          type = document.createAttribute("type");
          type.nodeValue = "number";
          ctl.setAttributeNode(type);
         }catch(err)  
        {
        alert(err);
        }   
      }); 
     </script>
    </head>

    <body>
      <apex:form id="frm" >    
      This is a numeric input <apex:inputfield id="txtNumeric" value="{!account.name}" style="width:200px;"  /> 
      </apex:form>
    </body>

</apex:page>