私のテキスト領域(inputbox div)でテキストを分割(配列に変換)し、resultという名前のdiv idで表示したいですか?テキストを配列に分割する
var txtBox = document.getElementById("inputbox");
var lines = txtBox.value.split("\n");
// print out last line to page
var blk = document.getElementById("result");
blk.innerHTML = lines[lines.length - 1];
<div id="result"></div>
<div id="singleQuote"></div>
<div id="inputbox" style="width: 710px;color: #ffffff;background: activecaption">
On the other hand,
<br/>we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of
</div>
をプリントアウトします私たちのほとんどは、おそらくあなたの問題を理解することはできません、より冗長にしてください。 –
私はあなたのJSからあなたが新しい行でテキストボックスの内容を分割しようとしていることを伝えることができます。私はこれに2つの問題を見る。 1:あなたやユーザが実際にそこに新しい行を置かない限り、何も分割しません.2:通常は要素が読み込めないことを意味する 'undefined'のプロパティ' split'を読むことができません。値のオブジェクトクラスを確認してください。私が理解しているところから、 'split'は文字列でしか動作しません。 –
doc reference:http://www.w3schools.com/jsref/jsref_split.asp –