我是JSF与PrimeFaces 5.1在我的项目需要onBlur删除指定字符即在文本01,02,03,,
或01,02,03
或01,02,03,,,,
这个文本框值我需要01,02,03
使用javascript是可能的或任何其他方式
使用这个trimRight方法:https://www.sitepoint.com/trimming-strings-in-javascript/
String.prototype.trimRight = function(charlist) {
if (charlist === undefined)
charlist = "s";
return this.replace(new RegExp("[" + charlist + "]+$"), "");
};
console.log("01,02,03,,,".trimRight(','));
var input = "01,02,03,,,,";
//Keep checking if the trailing character is ','
while(input && input.charAt(input.length-1) == ","){
//if true trim the last character and continue
input = input.substring(0,input.length-1);
}
console.log(input);