<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>One JavaScript instance per day - remove the blank at the end of the string</title> <script> function white(){ var input = document.getElementById("inputid"); var line = input.Value.split ("/n"); var resultString = ""; für (var i = 0; i <line.length; i ++) {var string = line [i] .trim (); resultString + = String + "-"; } alert (resultString); } </script> </head> <body> <textarea id = "inputID" placeholder = "Bitte geben Sie mehrere Zeilen von String ein"> </textArea> <a href = "#" onclick = "White ()"> ClickMe </a> </body> </html>Erkennen Sie Browser der unteren Version, rückwärts kompatibel:
if (typeof string.trim == "undefined") string.prototype.trim = function () {return this.replace (/(^/s*) | (/s*$)/g, ""); }}