我正在研究限制标记,因此max将为5,但对于此测试,我将使用2,但是在行尾有一个额外的逗号,当尝试添加另一个逗号时标签超过最大允许值。我如何删除逗号?删除行尾的额外逗号
<body>
<input id="input" type="text" />
</body>
$("#input").keypress(function(e){
var value = $(this).val().replace(" ", "");
var words = value.split(",");
if(words.length > 2){
//alert("Hey! That's more than 5 words!");
e.preventDefault();
}
});
DEMO:http://jsfiddle.net/BzN5W/2/
[RTRIM在javascript]的可能的复制(http://stackoverflow.com/questions/8791394/rtrim-in-javascript) – Rasclatt