我想为JavaScript中从00,00到99,99的百分比值获取一个掩码。
这个掩码需要接受任何值,这是可以接受的值,例如
1 11 11,1 11,11
这是我的代码:HTML:
<input id="per" type="text"></input>
和JS:
$("#per").mask("9?9,99");
但是当我尝试插入11
时,这个更改为11,
。在这种情况下,如何删除,
?
这是我的口罩:http://jsfiddle.net/SEXAj/2763/
您可以将其与模糊事件一起使用:
$("#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]
});
更新Fiddle。
这个不同的掩码插件https://igorescobar.github.io/jQuery-Mask-Plugin/做你想做的事。你可以试试,点击链接