我是JavaScript新手,我試圖將輸入框中的文本動態添加到段落中(在頁面頂部的2個標題下) 。使用JavaScript動態地將文本框的內容作爲段落文本插入
我有我與here
這是我的函數工作一個的jsfiddle:
function addText() {
var newParagraph = document.createElement('p');
newParagraph.textContent = textArea;
document.getElementById("id1").appendChild(newParagraph);
myDiv.insertBefore(newParagraph, textArea);
}
document.getElementById("textArea").onblur = addText;
然而,正如你所看到的,對的onblur,它是這樣做的:對象HTMLTextAreaElement]
我不知道我哪裏出錯了。
這個作品:http://jsfiddle.net/shannongmac/T7LeW/12/ – shannonmac