我尝试使用jquery keyboard.js从文本框中获取用户输入。如果省略虚拟键盘代码,它的工作正常。
网址:https://github.com/Mottie/Keyboard
我收到控制台错误
Uncaught TypeError: $(...).keyboard is not a function
我按照他们的说法做了以下导入,
<!-- jQuery (required) & jQuery UI + theme (optional) -->
<link href="docs/css/jquery-ui.min.css" rel="stylesheet">
<!-- still using jQuery v2.2.4 because Bootstrap doesn't support v3+ -->
<script src="docs/js/jquery-latest.min.js"></script>
<script src="docs/js/jquery-ui.min.js"></script>
<!-- <script src="docs/js/jquery-migrate-3.0.0.min.js"></script> -->
<!-- keyboard widget css & script (required) -->
<link href="css/keyboard.css" rel="stylesheet">
<script src="js/jquery.keyboard.js"></script>
<!-- keyboard extensions (optional) -->
<script src="js/jquery.mousewheel.js"></script>
<script src="js/jquery.keyboard.extension-typing.js"></script>
<script src="js/jquery.keyboard.extension-autocomplete.js"></script>
<script src="js/jquery.keyboard.extension-caret.js"></script>
<!-- demo only -->
<link rel="stylesheet" href="docs/css/bootstrap.min.css">
<link rel="stylesheet" href="docs/css/font-awesome.min.css">
<link href="docs/css/demo.css" rel="stylesheet">
<link href="docs/css/tipsy.css" rel="stylesheet">
<link href="docs/css/prettify.css" rel="stylesheet">
<script src="docs/js/bootstrap.min.js"></script>
<script src="docs/js/demo.js"></script>
<script src="docs/js/jquery.tipsy.min.js"></script>
<script src="docs/js/prettify.js"></script>
虚拟键盘的JavaScript代码:
$('#inputPassword').keyboard({
openOn : null,
stayOpen : true,
layout : 'qwerty'
})
.addTyping();
$('#password-opener').click(function(){
var kb = $('#inputPassword').getkeyboard();
// close the keyboard if the keyboard is visible and the button is clicked a second time
if ( kb.isOpen ) {
kb.close();
} else {
kb.reveal();
}
});
我尝试了几件事但我找不到解决方案。我在这里错过了什么?
答案 0 :(得分:2)
您必须将与JQuery相关的代码包含在DOM load ready事件中:
$(document).ready(function() {
$('#inputPassword').keyboard({
openOn : null,
stayOpen : true,
layout : 'qwerty'
})
.addTyping();
$('#password-opener').click(function(){
var kb = $('#inputPassword').getkeyboard();
// close the keyboard if the keyboard is visible and the button is clicked a second time
if ( kb.isOpen ) {
kb.close();
} else {
kb.reveal();
}
});
});