使用HTML输入类型的数字键盘显示

时间:2015-06-08 18:09:13

标签: android ios html5 input android-softkeyboard

由于用户在字段中输入的大部分值仅为数字和符号,因此我特别要求在iPhone和Android移动设备上在文本输入字段的焦点上显示数字符号键盘。但输入字段也可以接受字母字符。为了改善用户体验,我需要在字段焦点上显示数字符号键盘作为默认值。但是使用HTML5输入标签,我无法在iPhone和Android中实现这一点。

    require "../class/simple_html_dom.php";

    $USERNAME = 'iamtherealginger13@gmail.com';
    $PASSWORD = '******';
    $COOKIEJAR = 'cookies.txt';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $COOKIEJAR);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $COOKIEJAR);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
    curl_setopt($ch, CURLOPT_TIMEOUT, 120);

    curl_setopt($ch, CURLOPT_URL,
                'https://accounts.google.com/ServiceLogin?hl=en&service=alerts&continue=http://www.google.com/alerts/manage');
    $data = curl_exec($ch);
    $formFields = getFormFields($data);

    $formFields['Email']  = $USERNAME;
    $formFields['Passwd'] = $PASSWORD;
    unset($formFields['PersistentCookie']);

    $post_string = '';
    foreach($formFields as $key => $value) {
      $post_string .= $key . '=' . urlencode($value) . '&';
    }

    $post_string = substr($post_string, 0, -1);
    curl_setopt($ch, CURLOPT_URL, 'https://accounts.google.com/ServiceLoginAuth');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);

    $result = curl_exec($ch);

    curl_setopt($ch, CURLOPT_URL, "https://accounts.google.com/o/oauth2/auth?response_type=code&scope=https://gdata.youtube.com&access_type=offline&redirect_uri=urn:ietf:wg:oauth:2.0:oob&pageId=none&client_id=911313852664-tir6o945mdn2bouorh\
        palkecrg23dng9.apps.googleusercontent.com&hl=fr&from_login=1&as=-5df191bb4410a26d&pli=1&authuser=0");
    curl_setopt($ch, CURLOPT_POST, 0);
    curl_setopt($ch, CURLOPT_POSTFIELDS, null);

    $result = curl_exec($ch);
    echo $result;
    // AFFICHE LA PAGE AVEC LE BOUTON ACCEPTER
    $formFields = getFormFieldsAccess($result);
    $formFields["bgresponse"] = "js_disabled";
    $formFields["submit_access"] = "true";
    $post_string = '';
    foreach($formFields as $key => $value) {
      $post_string .= $key . '=' . $value . '&';
    }
    $post_string = substr($post_string, 0, -1);
    echo 'Donneees post : ';

    preg_match_all('!https://accounts[\S]+!', $result, $matches);
    $all_urls = $matches[0][2];
    $all_urls = urldecode(substr($all_urls, 0, -1));
    var_dump($all_urls);

    curl_setopt($ch, CURLOPT_URL, $all_urls);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
    curl_setopt($ch, CURLOPT_REFERER, 'https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/youtube.upload&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&client_id=911313852664-tir6o945mdn2bouorhpalkecr\
    g23dng9.apps.googleusercontent.com&access_type=offline&pageId=none');
    $result = curl_exec($ch);
    echo $result;

根据W3标准,输入类型=数字只接受数值和小数分隔符。即使我们能够输入其他符号,也会以表格提交方式发送无效号码。因此,输入类型=数字不适合此要求。

enter image description here

我希望在输入字段的焦点上显示图像中显示的第二个键盘作为默认键盘。由于我的目标是网页和厚应用程序,自定义键盘是不可行的解决方案。是否有人建议实现这一目标?

1 个答案:

答案 0 :(得分:2)

您无法在Android中强制使用特定布局。您可以告诉键盘类型,例如数字(Android中有几种类型的数字,但html并不是那么丰富)。键盘是一个单独的应用程序,然后决定显示什么键盘。根据特定键盘认为最好的内容,它可能显示9-pad,单个数字行,甚至忽略您的请求。但是没有办法强制使用特定的设计,也无法保证键盘甚至支持这种设计。

此外,对于类似这样的事情,即使可行,自定义键盘也不是一个好的答案。用户不喜欢键盘被更改,如果你这样做,你最好有充分的理由。原因"我更喜欢这种布局更好的数字"不是一个好理由。在这种情况下,您需要放弃该要求。