日期:2014-05-16 浏览次数:20480 次
function show() { var a = "文本,文本,文本"; if(a.substring(a.length-1,a.length) != ",") { a = a+","; } alert(a); }
------解决方案--------------------
没看清还有前面要加“,”
function show() { var a = "文本,文本,文本"; if(a.substring(a.length-1,a.length) != ",") { a = a+","; } if(a.substring(0,1) != ",") { a = ","+a; } alert(a); }