我的函数 valueS() 由于某种原因不起作用,它不会触发底部的 ajax 函数......由于某种原因 bind('change keyup input') 在添加空格时不会触发。
如何修复函数 valueS() 以触发底部函数?
$(document).keypress(function(event) {
switch(event.which){
case 32:
if(!$('input').is(':focus')){
event.preventDefault();
valueS();
}
break;
//other cases not shown here
}
function valueS(){
var value = parseInt(document.getElementById('id1').value, 10);
value = isNaN(value) ? "" : value;
document.getElementById('id1').value = "" + value + " ";
}
$(document).ready(function(e){
$('#id1').bind('change keyup input', function(ev) {
if(/\s/.test($(this).val())){
// removes space
this.value = this.value.replace(/[\s]/g, '');
// submits ajax
if(this.value.length>0)
ajax_post();
// clears input
$('input[id=id1]').val('');
}
});