我有一个带掩码的输入框,但硬件键盘不允许输入,而是只有触摸屏keyboard()
功能,只插入该字段中的字符。
但是当keyboard()
在输入字段中插入输入时,它无法生成掩码效果。
如何在使用keyboard()
时使面具也能正常工作?
<script type="text/javascript" src="http://digitalbush.com/wp-content/uploads/2014/10/jquery.maskedinput.js"></script>
<script type="text/javascript">
function keyboard(input) {
if (input==='BACKSPACE') {
tvalue = '';
} else if(input ==='QUOTE') {
tvalue = tvalue + "'";
} else if(input ==='SPACE') {
tvalue = tvalue + " ";
} else {
tvalue = tvalue + input;
}
$('#' + tinput).val(tvalue);
console.log(">>> Keyboard: ", input);
}
$(document).ready(function(){
$("#rrn").mask('99.99.99-999.99');
// $(document).bind('contextmenu', function() {
// console.log('Touch screen, has no right click.');
// return false;
// });
//
// $(document).mousedown( function() {
// return false;
// });
});
</script>
<div>
<input type="text" name="rrn" id="rrn" style="position: absolute; left: 519px; top: 195px; width: 366px; height: 42px;border:none;" autocomplete="off" onclick="inputselected(this, event);"/>
<img src="images/nl/keyboard.png" border="0" usemap="#map_logo_new" id="spmain_new" />
<map name="map_logo_new">
<area shape="rect" coords="825,19,910,74" href="#" onclick="keyboard(0);">
<area shape="rect" coords="22,83,107,138" href="#" onclick="keyboard('A');">
</map>
</div>
答案 0 :(得分:2)
您正在以编程方式设置输入的值,这不会导致任何事件触发。为了强制应用蒙版,您需要自己触发事件(在调用.val()
之后)。
尝试更改为:
$('#' + tinput).val(tvalue).trigger('input');
这是来自Josh Bush在digitalbush.com上的jQuery Masked Input Plugin。
此时此库的最新版本为v1.4。对于库的早期版本,您可能必须尝试'click'
事件。