2011-10-11 58 views
0

input驗證了一些不工作,這裏的全碼:http://jsfiddle.net/aVF7M/驗證通過JavaScript的一些在HTML輸入不起作用

$('.number').each(function(){ 
    $(this).bind('keyup change',function(){ 
     $(this).val($(this).val().replace(/\D/g,'')); 
    }); 
}); 


$('a.add_input').live('click', function (event) { 
    event.preventDefault(); 
    num() 
    var $class = '.' + $(this).closest('div.find_input').find('div').attr('class').split(" ")[0]; 
    var size_un = $($class).length; 
    var $this = $(this), 
     $div = $this.closest($class), 
     $clone = $div.clone().hide().insertAfter($div).fadeIn('slow'); 
    $clone.find('.remove_table').remove(); 
    $clone.find('.adda').not(':has(.remove_input)').append('<div class="mediumCell"><a href="" class="remove_input"></a></div>'); 
    $clone.find('input:checkbox').prop('checked', false); 
    $clone.find('input:text').val('') 
    $this.remove(); 
    var size_un = $($class).length---1; 
    $($class + ':last input:checkbox').prop('name', 'checkbox_units[' + size_un + '][]'); 
    console.log($($class + ':last input:checkbox').prop('name')); 
}); 
+1

能否請你清理你的代碼,並僅作爲相關的問題提供儘可能多在眼前? –

+0

'num()'是什麼? –

回答

0

考慮您已經定義NUM()和它的作品。

正如你所添加的input.number動態,你需要使用活 -

$('.number').live('keyup change',function(){ 
    $(this).val($(this).val().replace(/\D/g,'')); 
}); 

演示http://jsfiddle.net/aVF7M/1/

+1

所有那些jQuery對象和函數調用來獲取和設置一個可以直接訪問的屬性:'this.value = this.value.replace(/ \ D/g,'')'是非常快。 – RobG