<!doctype html> <html> <head> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"/> <title> 1日あたり1つのjavascriptインスタンス - 文字列の最後にブランクを削除しますvar lines = input.value.split( "/n"); var resultString = ""; for(var i = 0; i <lines.length; i ++){var string = lines [i] .trim(); resultString + = string + " - "; } alert(resultString); } </script> </head> <body> <textarea id = "inputId" placeholder = "低いバージョンのブラウザを検出します。後方互換性:
if(typeof string.trim == "undefined")string.prototype.trim = function(){return this.replace(/(^/s*)|(/s*$)/g、 ""); }}