如果我不知道字符串有多大,如何从字符串中删除最后一行“\n”?vartempHTML=content.document.body.innerHTML;varHTMLWithoutLastLine=RemoveLastLine(tempHTML);functionRemoveLastLine(tempHTML){//code} 最佳答案 尝试:if(x.lastIndexOf("\n")>0){returnx.substring(0,x.lastIndexOf("\n"));}else{returnx;}