开发者

Validating a number in HTML input via JavaScript doesn't work

Validating a number in input doesn't work, here's the full code: http://jsfiddle.net/aVF7M/

$('.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 + 开发者_JAVA技巧':last input:checkbox').prop('name'));
});


Considering you have defined num() and it works.

As you are adding the input.number dynamically you would need to use live -

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

Demo http://jsfiddle.net/aVF7M/1/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜