我是PrimeFaces 5.1的JSF,我的项目需要onBlur删除指定字符,即在文本01,02,03,,
或01,02,03
或01,02,03,,,,
这个文本框值我需要01,02,03
使用javascript可能或任何其他方式
答案 0 :(得分:1)
使用此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(','));

答案 1 :(得分:0)
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);