Iphone Development - How to display a numeric keyboard?

前端 未结 3 869
傲寒
傲寒 2021-01-05 06:52

I\'m working on a mobile website which is NOT a native iPhone app but rather a simple m.somedomain.com website which is developed in c# asp.net .

Objective : On clic

相关标签:
3条回答
  • 2021-01-05 07:34

    For Salesforce (not HTML input type='number'), below java-script should make the iPad, iPhone numeric keypad defaultly appear. (This solution should work for asp.net control as well)

        <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>
    
    0 讨论(0)
  • 2021-01-05 07:38

    If you use type="tel" instead of type="text" it will bring up a numeric keyboard.

    0 讨论(0)
  • 2021-01-05 07:53

    EDIT: I found here that you can use

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

    to tell mobile safari to set the numeric keyboard as default, without needing to specify the telephone keyboard.

    EDIT 2 (from comments below): You can also use javascript to force numeric input as so:

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

    0 讨论(0)
提交回复
热议问题