我想制作一个"NumPad",我可以在输入字段中输入一个4位数的键码.单击四个按钮后,按下提交按钮.我发现了一些代码片段,如果我使用键盘,它就可以工作了.这是我走了多远:
function addNum(num){
document.getElementById('login').value += num;
}
$('#login').keyup(function(){
if(this.value.length == 4){
$('#enter').click();
}
});Run Code Online (Sandbox Code Playgroud)
#numpad {
width: 200px;
}
.row {
width: 100%;
}
.number {
min-width: 26%;
height: 60px;
float: left;
border: 1px solid;
margin: 10px;
vertical-align: middle;
display: block;
font-size: 2em;
padding-top: 8px;
padding-left: 30px;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
}
a:hover .number {
background: black;
color: white;
}Run Code Online (Sandbox Code Playgroud)
<form action="action.php" method="post" name="loginform" id="loginform">
<input type="password" class="form-control" name="login" id="login">
<input type="submit" id="enter" value="Submit">
</form>
<div id="numpad">
<div …Run Code Online (Sandbox Code Playgroud)对不起,我还没写完全文就发了。。
单击提交按钮后出现错误:
错误日志
TypeError: undefined has no properties
[Weitere Informationen]
jquery.validate.min.js:4:22946
a.ajax
https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.min.js:4:22946
submitHandler
http://suedsicht-projekte.de/opus/newsletter-daten/landingpage/js/main.js:13:7
d
https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.min.js:4:962
validate/<
https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.min.js:4:1173
dispatch
https://code.jquery.com/jquery-3.2.1.slim.min.js:3:10499
add/q.handle
https://code.jquery.com/jquery-3.2.1.slim.min.js:3:8561
Run Code Online (Sandbox Code Playgroud)
该脚本在另一个站点上工作。但这一次它不起作用:(
JS
$(document).ready(function(){
$("#teilnahme").validate({
rules: {
inputVorname: { required: true }
},
messages: {
inputVorname: { required: "Bitte tragen Sie Ihren Vornamen ein." }
},
submitHandler: function(form) {
theUrl = 'teilnahme.php';
var params = $(form).serialize();
$.ajax ({
type: "POST",
url: theUrl,
data: params,
processData: false,
async: false,
success: function(result) {
$("#sendbutton").fadeOut(100).hide(function(){
$("#successbutton").fadeIn(100).show(function(){
$(".result").html(data);
});
});
}
}); …Run Code Online (Sandbox Code Playgroud)