Javascript 如何使用mottie键盘输入美分并将其保留在那里?
我快疯了。。。我已经花了16个多小时试图让这件事运作起来,如果有人对这种邪恶行为的原因有任何线索,请提供建议 我在一个表单中有多个数字类型的输入,我将键盘连接到每个输入,如下所示:Javascript 如何使用mottie键盘输入美分并将其保留在那里?,javascript,jquery,jquery-ui,keyboard,uikeyboard,Javascript,Jquery,Jquery Ui,Keyboard,Uikeyboard,我快疯了。。。我已经花了16个多小时试图让这件事运作起来,如果有人对这种邪恶行为的原因有任何线索,请提供建议 我在一个表单中有多个数字类型的输入,我将键盘连接到每个输入,如下所示: $('.amount').keyboard({ layout: 'custom', customLayout : { 'normal' : ['1 2 3', '4 5 6', '7 8 9','{clear} 0 {bksp}','{accept}'] }, displ
$('.amount').keyboard({
layout: 'custom',
customLayout : {
'normal' : ['1 2 3', '4 5 6', '7 8 9','{clear} 0 {bksp}','{accept}']
},
display : {
'accept' : 'Confirm:Confirm (Shift-Enter)',
'bksp' : 'Delete:Delete',
'clear': 'Clear:Clear'
},
beforeVisible: function(e, keyboard, el) {
$("#"+keyboard.$keyboard[0].id).addClass("hide-me");
},
restrictInput: true,
preventPaste: true,
autoAccept: true,
usePreview: false,
useWheel: false,
repeatRate: 0,
// this function is so I can display cents in the input
// there is no decimal in the keyboard as part of the requirements
change: function(e, keyboard, el) {
if (el.value === null || el.value === "") {
el.value = "0.00";
}
el.value = parseInt(el.value);
el.value = el.value * 0.01;
},
// this function is so I can display cents in the inputs
// there is no decimal in the keyboard as part of the requirements
accepted: function(e, keyboard, el) {
if (el.value === null || el.value === "") {
el.value = "0.00";
}
el.value = parseInt(el.value);
el.value = el.value * 0.01;
},
caretToEnd: 'true',
maxLength : '20',
css: {
container: 'center-block dropdown-menu custom-keypad',
buttonDefault: 'btn-kb',
buttonHover: 'btn-primary',
buttonAction: 'active',
buttonDisabled: 'disabled'
}
});
$('form').on('change', '.amount', function () {
var balance = NUMBER;
var sum = 0;
$(".amount").each(function (){
var valTotal = Number($(this).val());
if (!isNaN(valTotal)) {
sum += valTotal;
}
});
if (sum > balance) {
//stuff happens
}
});//.end of form
键盘弹出,当我输入和确认输入时,我可以正确地看到输入中的小数。我的目标是将所有input.val()相加,并在表单发生任何更改时立即验证它们。这样做的功能如下所示:
$('.amount').keyboard({
layout: 'custom',
customLayout : {
'normal' : ['1 2 3', '4 5 6', '7 8 9','{clear} 0 {bksp}','{accept}']
},
display : {
'accept' : 'Confirm:Confirm (Shift-Enter)',
'bksp' : 'Delete:Delete',
'clear': 'Clear:Clear'
},
beforeVisible: function(e, keyboard, el) {
$("#"+keyboard.$keyboard[0].id).addClass("hide-me");
},
restrictInput: true,
preventPaste: true,
autoAccept: true,
usePreview: false,
useWheel: false,
repeatRate: 0,
// this function is so I can display cents in the input
// there is no decimal in the keyboard as part of the requirements
change: function(e, keyboard, el) {
if (el.value === null || el.value === "") {
el.value = "0.00";
}
el.value = parseInt(el.value);
el.value = el.value * 0.01;
},
// this function is so I can display cents in the inputs
// there is no decimal in the keyboard as part of the requirements
accepted: function(e, keyboard, el) {
if (el.value === null || el.value === "") {
el.value = "0.00";
}
el.value = parseInt(el.value);
el.value = el.value * 0.01;
},
caretToEnd: 'true',
maxLength : '20',
css: {
container: 'center-block dropdown-menu custom-keypad',
buttonDefault: 'btn-kb',
buttonHover: 'btn-primary',
buttonAction: 'active',
buttonDisabled: 'disabled'
}
});
$('form').on('change', '.amount', function () {
var balance = NUMBER;
var sum = 0;
$(".amount").each(function (){
var valTotal = Number($(this).val());
if (!isNaN(valTotal)) {
sum += valTotal;
}
});
if (sum > balance) {
//stuff happens
}
});//.end of form
问题从这里开始,当我对输入求和时,我的小数消失了!以前的22.22现在是2222,所以我的总数是错误的,导致我的总数总是比我的余额大。我试图创建一个小提琴,但它不会弹出结果框上的键盘,所以我无法向您展示一个真实的例子
这是我正在使用的CDN:
请指教 所以我与插件的创建者取得了联系,他很友好地通过电子邮件回答了我的问题。他的解决方案非常有效 你可以在这里看到小提琴。。 主要问题是$('.amount')选择器包含一个隐藏的重复输入,因此他将其更改为$(“.amount:not(:disabled)”) 在“accepted”上进行格式化之后,他还执行了sum()操作 工作完美=)