Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过JavaScript验证HTML输入中的数字不会';行不通_Javascript_Jquery_Html - Fatal编程技术网

通过JavaScript验证HTML输入中的数字不会';行不通

通过JavaScript验证HTML输入中的数字不会';行不通,javascript,jquery,html,Javascript,Jquery,Html,验证输入中的数字无效,以下是完整代码: $('.number')。每个(函数(){ $(this.bind('keyup change',function()){ $(this.val($(this.val().replace(/\D/g'); }); }); $('a.add_input').live('click',函数(事件){ event.preventDefault(); num() var$class='.+$(this).closest('div.find_input').find

验证
输入中的数字无效,以下是完整代码:

$('.number')。每个(函数(){
$(this.bind('keyup change',function()){
$(this.val($(this.val().replace(/\D/g');
});
});
$('a.add_input').live('click',函数(事件){
event.preventDefault();
num()
var$class='.+$(this).closest('div.find_input').find('div').attr('class').split(“”[0]);
var size_un=$($类).length;
变量$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('');
$clone.find('input:checkbox').prop('checked',false);
$clone.find('input:text').val('')
$this.remove();
var size_un=$($类).length--1;
$($class+':上次输入:checkbox').prop('name','checkbox_units['+size_un+'][]);
console.log($($class+':上次输入:checkbox').prop('name');
});

考虑到您已经定义了num(),并且它可以工作

在动态添加input.number时,您需要使用live-

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

Demo

您可以清理代码,只提供与当前问题相关的内容吗?所有这些jQuery对象和函数调用都可以直接访问并设置属性:
this.value=this.value.replace(/\D/g')
的速度要快得多。
$('.number').live('keyup change',function(){
    $(this).val($(this).val().replace(/\D/g,''));
});