0
我的函數valueS()由於某種原因不起作用,它不會觸發底部的ajax函數...出於某種原因bind('change keyup input')不會觸發當一個空間被添加時。用空格鍵觸發ajax
如何解決函數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('');
}
});
這完美的作品!謝謝! –
沒問題 - 很高興幫助:) – Archer