Javascript 任何值的jQuery掩码百分比
我想获得JavaScript中百分比值的掩码,从00,00到99,99 此掩码需要接受任何值,例如,这是可以接受的值 11111,11111,11 这是我的代码: HTML: 但是,当我尝试插入Javascript 任何值的jQuery掩码百分比,javascript,jquery,mask,percentage,Javascript,Jquery,Mask,Percentage,我想获得JavaScript中百分比值的掩码,从00,00到99,99 此掩码需要接受任何值,例如,这是可以接受的值 11111,11111,11 这是我的代码: HTML: 但是,当我尝试插入11时,会将此更改为11,。在这种情况下,如何删除, 这是我的遮罩:您可以将其用于模糊事件: $("#per").mask("9?9,99").blur(function(){ var rg = /\,+\d/g; // regular expression for comma and number
11
时,会将此更改为11,
。在这种情况下,如何删除,
这是我的遮罩:您可以将其用于模糊事件:
$("#per").mask("9?9,99").blur(function(){
var rg = /\,+\d/g; // regular expression for comma and number
if(!rg.test(this.value)){ // check if value doesn't have any num after comma
this.value = this.value.split(',')[0]; // then just split the value and
} // assign the index[0]
});
您可以将此选项用于模糊事件:
$("#per").mask("9?9,99").blur(function(){
var rg = /\,+\d/g; // regular expression for comma and number
if(!rg.test(this.value)){ // check if value doesn't have any num after comma
this.value = this.value.split(',')[0]; // then just split the value and
} // assign the index[0]
});
这个不同的掩码插件正是您想要的。您可以尝试一下,按照链接进行操作。这个不同的掩码插件正是您想要的。您可以试试,请点击链接,您能在这里添加代码吗?JSFIDLE还可以,但是您应该在这里发布代码!没有其他内容,只有此
$('#per').val()。请使用正则表达式替换(/,$/,'')
,并将结尾逗号替换为空字符串。请在此处添加代码?JSFIDLE还可以,但是您应该在这里发布代码!没有别的了,只有这个$('#per').val()。用正则表达式替换(/,$/,'')
,并用空字符串替换结尾的逗号。我不能更改pluginI不能更改pluginI试试这个,但是$(“#per”)的输出。val()保持“11”,@gFontaniva你检查过小提琴吗?做一件事检查控制台是否有错误。我尝试了这个,但是$(“#per”).val()的输出保持为“11”,@gFontaniva您检查过小提琴了吗?做一件事检查控制台是否有任何错误。
$("#per").mask("9?9,99").blur(function(){
var rg = /\,+\d/g; // regular expression for comma and number
if(!rg.test(this.value)){ // check if value doesn't have any num after comma
this.value = this.value.split(',')[0]; // then just split the value and
} // assign the index[0]
});