在输入焦点上打开Windows 10触摸键盘的数字版本

时间:2019-03-08 12:40:05

标签: javascript php jquery html windows

我创建了一个自助前台网站。
显示此网站的计算机将只有一个触摸屏。没有硬件键盘或鼠标。只需触摸屏。
您可以选择要见面的员工
它将打开一个包含3个输入字段的表单:姓名,电话号码和电子邮件。

我希望用户单击电话号码输入字段时弹出数字屏幕键盘。

对于手机,我会使用以下任何选项:

type="text" pattern="\d*"
type="number" pattern="[0-9]*" inputmode="numeric"

但是对于Windows 10屏幕键盘,此功能不起作用。
关于如何强制数字小键盘打开的任何想法吗?
我只在Google Chrome浏览器上测试过。也许其他浏览器可以更好地处理此问题。
也许这不可能...

赞赏其他方法。

1 个答案:

答案 0 :(得分:0)

还有一种替代方法,以防在Windows上无法实现:
证明:CodePen
我使用Mottie jQuery虚拟键盘重新创建了Windows10版本的屏幕键盘。您可以选择显示哪些键并创建自己的数字键盘版本。

html

<input type="text" id="phone" name="iauysdyd" maxlength="7" minlength="7" class="form-control required" data-error="Ritaðu símanúmer" placeholder="PhoneNumber" autocomplete="off" required>


JavaScript ,它创建虚拟键盘的小键盘版本:

$("input#phone").
    keyboard({
        maxLength : 7,
        usePreview: false,
        autoAccept: true,
        language: ['Icelandic'],
        lang: ['is'],
        layout: "custom",
        customLayout: {
            normal: [
                "7 8 9", // choose your own keys here
                "4 5 6", // choose your own keys here
                "1 2 3", // choose your own keys here
                "0 {bksp}" // choose your own keys here
                ]
        } 
    });


最后是一些 CSS ,使其看起来像Windows 10版本的OSK:

body .ui-keyboard-input {
    text-align: center !important;
}
.ui-keyboard.ui-widget {
    bottom: 0%;
    left: 0;
    top: unset !important;
    position: absolute;
    width: 100%;
    background-color: #303030;
    background-size: 100%;
}

.ui-keyboard.ui-widget .ui-keyboard-button {
    font-size:1.4em;
    height: 2em;
    min-width: 2em;
    font-weight: 100;
    color: #fff;
}
button.ui-keyboard-button {
    background: #5d5d5d;
    border: 0px;
}
.ui-keyboard-shift span {
  background: url('data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20version%3D%221.1%22%20id%3D%22Capa_1%22%20x%3D%220px%22%20y%3D%220px%22%20viewBox%3D%220%200%20525.153%20525.153%22%20style%3D%22enable-background%3Anew%200%200%20525.153%20525.153%3B%22%20xml%3Aspace%3D%22preserve%22%20width%3D%22512%22%20height%3D%22512%22%20class%3D%22%22%3E%3Cg%3E%3Cg%3E%0A%09%3Cpath%20d%3D%22M169.974%2C401.567H355.2V216.21h123.586L262.576%2C0L46.367%2C216.21h123.586v185.357H169.974z%20M46.367%2C463.294h432.419v61.859%20%20%20H46.367V463.294z%22%20data-original%3D%22%23000000%22%20class%3D%22active-path%22%20style%3D%22fill%3A%23FFFFFF%22%20data-old_color%3D%22%23DAA3A3%22%3E%3C%2Fpath%3E%0A%3C%2Fg%3E%3C%2Fg%3E%20%3C%2Fsvg%3E') center center no-repeat;
    background-size: 20px;
    display: block;
    margin: auto;
    width: 30px;
    height: 30px;
    text-indent: -999em;
}
/* target greek letter alpha */
.ui-keyboard-bksp span {
    background: url('data:image/svg+xml;utf8,%3Csvg%20version%3D%221.1%22%20id%3D%22Capa_1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20x%3D%220px%22%20y%3D%220px%22%0A%09%20viewBox%3D%220%200%20489.425%20489.425%22%20style%3D%22enable-background%3Anew%200%200%20489.425%20489.425%3B%22%20xml%3Aspace%3D%22preserve%22%3E%0A%3Cg%3E%0A%09%09%3Cpath%20style%3D%22fill%3A%23fff%3B%22%20d%3D%22M122.825%2C394.663c17.8%2C19.4%2C43.2%2C30.6%2C69.5%2C30.6h216.9c44.2%2C0%2C80.2-36%2C80.2-80.2v-200.7c0-44.2-36-80.2-80.2-80.2h-216.9%0A%09%09%09c-26.4%2C0-51.7%2C11.1-69.5%2C30.6l-111.8%2C121.7c-14.7%2C16.1-14.7%2C40.3%2C0%2C56.4L122.825%2C394.663z%20M29.125%2C233.063l111.8-121.8%0A%09%09%09c13.2-14.4%2C32-22.6%2C51.5-22.6h216.9c30.7%2C0%2C55.7%2C25%2C55.7%2C55.7v200.6c0%2C30.7-25%2C55.7-55.7%2C55.7h-217c-19.5%2C0-38.3-8.2-51.5-22.6%0A%09%09%09l-111.7-121.8C23.025%2C249.663%2C23.025%2C239.663%2C29.125%2C233.063z%22%2F%3E%0A%09%09%3Cpath%20style%3D%22fill%3A%23fff%3B%22%20d%3D%22M225.425%2C309.763c2.4%2C2.4%2C5.5%2C3.6%2C8.7%2C3.6s6.3-1.2%2C8.7-3.6l47.8-47.8l47.8%2C47.8c2.4%2C2.4%2C5.5%2C3.6%2C8.7%2C3.6s6.3-1.2%2C8.7-3.6%0A%09%09%09c4.8-4.8%2C4.8-12.5%2C0-17.3l-47.9-47.8l47.8-47.8c4.8-4.8%2C4.8-12.5%2C0-17.3s-12.5-4.8-17.3%2C0l-47.8%2C47.8l-47.8-47.8%0A%09%09%09c-4.8-4.8-12.5-4.8-17.3%2C0s-4.8%2C12.5%2C0%2C17.3l47.8%2C47.8l-47.8%2C47.8C220.725%2C297.263%2C220.725%2C304.962%2C225.425%2C309.763z%22%2F%3E%0A%3C%2Fg%3E%0A%3C%2Fsvg%3E') center center no-repeat;
    background-size: 40px;
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
    text-indent: -999em;
}
.ui-keyboard-bksp {
    width: 103px;
}
/* needed for inline image (second method below) */
.ui-keyboard-button {
  vertical-align: middle;
}

您可能可以做一些动画来使键盘像Windows 10一样向上滑动。
这将使您有一个很长的路来重新创建Windows 10 OSK的精确副本。