gpt4 book ai didi

javascript - 无法将虚拟键盘 jQuery 插件与 Angular 4 +Webpack 一起使用

转载 作者:行者123 更新时间:2023-11-30 14:58:09 36 4
gpt4 key购买 nike

我正在尝试在 Asp Core +webpack 的 Angular 4 模板上使用虚拟键盘我已经安装了 npm install --save-dev @types/virtual-keyboard在 webpack.config.vendor.js 我放了这一行:

const treeShakableModules = [
.....
'virtual-keyboard',
...
];

在我的组件模板中:

<input id="mycontrol" type="text">

在 .ts 中:

import * as jQuery from "jquery";
import { KeyboardOptions, NavigateOptions } from "virtual-keyboard";

const kbOptions: KeyboardOptions = {
display: {
bksp: "\u2190",
accept: `Next`,
cancel: `Back`,
normal: "ABC",
meta1: "#+-",
space: "Space",
alt: `Alt`,
s: `ABC`,
},
acceptValid: true,
type: "input",
layout: "custom",
customLayout: {
normal: [
`a b c d e f g h i j k l m`,
`n o p q r s t u v x y z w`,
`1 2 3 4 5 6 7 8 9 0 . _ @`,
`{alt} {s} {space} {meta1} {s} {bksp} `,
`{cancel} {accept}`
],
shift: [
`A B C D E F G H I J K L M`,
`N O P Q R S T U V X Y Z W`,
`1 2 3 4 5 6 7 8 9 0 . _ @`,
`{alt} {s} {space} {meta1} {s} {bksp} `,
`{cancel} {accept}`
],
meta1: [
`- / : ; ( ) \u20ac & \" ! ? ' \``,
`[ ] { } # % ^ * + = ° ´ §`,
` \\ | ~ < > $ \u00a3 \u00a5 , ' ² ³`,
`{space} {meta1} {bksp}`,
`{cancel} {accept}`
],
"alt-shift": [
`A B C D E F G H I J K L M N O`,
`P Q R S T U V X Y Z W \u00df \u00dc \u00d6 \u00c4`,
`1 2 3 4 5 6 7 8 9 0 . _ @ \u0301`,
`{alt} {s} {space} {meta1} {s} {bksp} `,
`{cancel} {accept}`
],
alt: [
`a b c d e f g h i j k l m n o`,
`p q r s t u v x y z w \u00df \u00fc \u00f6 \u00e4`,
`1 2 3 4 5 6 7 8 9 0 . _ @ \u0301`,
`{alt} {s} {space} {meta1} {s} {bksp} `,
`{cancel} {accept}`
],
},
lockInput: true,
alwaysOpen: true,
appendLocally: true,
color: "light",
class: "sxcycx",
updateOnChange: true,
usePreview: false,
tabNavigation: false,
canceled: () => { console.log("cancelled"); }
};

const navOptions: NavigateOptions = {
position: [0, 0],
toggleMode: true,
focusClass: "hasFocus",
rowLooping: true,
};

然后

ngAfterViewInit(): any {
try {



jQuery('#mycontrol').css("background-color", "red"); //I see the change
jQuery('#mycontrol').keyboard(kbOptions).addNavigation(navOptions);

....

在控制台中没有错误但是聚焦文本框没有显示键盘我觉得webpack.config.vendor.js里面肯定有东西要放

谢谢

最佳答案

通过 npm 安装 jquery 和虚拟键盘。试试这个:

// In *.ts file:
import * as $ from 'jquery';
import 'virtual-keyboard';

$('.vk').keyboard({
change: (e, keyboard, el) => {
// Dispatch input event to notify angular about changes
const inputEvent: any = document.createEvent('CustomEvent');
inputEvent.initEvent('input', true, true);
el.dispatchEvent(inputEvent);
}
});

//在 scss 中:

@import "../../node_modules/virtual-keyboard/dist/css/keyboard-dark.min";

顺便说一句,为了能够订阅虚拟键盘事件,最好在那里创建指令并初始化键盘。

关于javascript - 无法将虚拟键盘 jQuery 插件与 Angular 4 +Webpack 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46929097/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com