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

标签 javascript php jquery html windows

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

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

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

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

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

赞赏替代方法。

最佳答案

如果这在 Windows 上不可行,还有一个替代方法:
证明:CodePen
我使用 Mottie 重新创建了 Windows10 版本的屏幕键盘jQuery 虚拟键盘。您可以选择显示哪些键并创建您自己的小键盘版本。

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 的精确副本方面走得更远。

关于javascript - 在输入焦点上打开 Windows 10 触摸键盘的数字版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55063435/

相关文章:

javascript - 如何使用 Angular JS 正确地遍历数组元素?

javascript - 监视在被拒绝的 promise 中调用的函数

php - 简单的破旧,全面的 phpDocumentor 教程?

php - 一个 mysqli 连接用于多个数据库功能

JavaScript 语法 : const pureComponentPrototype = (PureComponent. 原型(prototype) = new ComponentDummy());

javascript - 半圆弧滚动javascript

php - 如何从 PDF 或各种其他文档文件创建缩略图?

jquery - 出现错误 : "$(...).carousel is not a function" although I've included JQuery, Bootstrap.min.css 和 Bootstrap.min.js

javascript - 当我似乎不需要匿名函数时,Javascript/JQuery 中匿名函数的目的是什么?

javascript - 单击后未隐藏wordpress移动菜单