テキストエリアに入力された文字列を縦書きに変換して表示するjavascriptソース。
縦書きになる商品を注文するフォームのプレビューや、縦書きソース作成なんかに便利かもしれない。
1 2 | < input type = "text" id = "text" size = "30" /> < div id = "preview" ></ div > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | var inputArea,preview; window.onload = function (){ inputArea = document.getElementById( "syuuha" ); preview = document.getElementById( "preview" ); inputArea.onkeyup = function (){ preview.innerHTML = TextSlice( this .value); } } function TextSlice(txt){ var max = txt.length; var array = []; for (i = 0; i < max ; i++) { var str = txt.charAt(i); array.push(str); } return array.join( "<br />" ); } |
文字列をバラして作った配列を改行タグで繋いでるだけなので、句点や小文字の処理とかは特にしてません。
divをtextareaにして、preview.innerHTMLをpreview.valueにすると、縦書きのhtmlソースが取得出来ます。