我希望在字符串达到14个字符时自动删除字符串的内容.
if(txt.length > 14){
alert("");
var res=texto.replace(texto.length," ");
alert(res);
}
Run Code Online (Sandbox Code Playgroud)
我试图做一个替换,但它失败了,任何想法?
你的示例代码非常令人困惑,因为它并没有真正说明什么被替换在哪里,但是说明显而易见的(如评论中所提到的):
var txt = "some long text maybe?";
if(txt.length > 14){
txt = "";
}
Run Code Online (Sandbox Code Playgroud)