才知道這個元素這麼詐欺……
<textarea>這是文字<textarea>
用chrome的檢查元素功能就能看出,這個textarea的各項內容如下:
顯示/隱藏
accessKey: ""
attributes: NamedNodeMap
autofocus: false
childElementCount: 0
className: ""
cols: 20
contentEditable: "false"
dataset: Object
defaultValue: "這是文字"
dir: ""
disabled: false
draggable: false
firstChild: Text
firstElementChild: null
form: null
hidden: false
innerHTML: "這是文字"
innerText: ""
isContentEditable: false
lang: ""
lastChild: Text
lastElementChild: null
localName: "textarea"
maxLength: -1
name: ""
namespaceURI: "http://www.w3.org/1999/xhtml"
nextElementSibling: HTMLTableElement
nextSibling: Text
nodeName: "TEXTAREA"
nodeType: 1
nodeValue: null
offsetHeight: 38
offsetLeft: 10
offsetParent: HTMLBodyElement
offsetTop: 138
offsetWidth: 181
onabort: null
onbeforecopy: null
onbeforecut: null
onbeforepaste: null
onblur: null
onchange: null
onclick: null
oncontextmenu: null
oncopy: null
oncut: null
ondblclick: null
ondrag: null
ondragend: null
ondragenter: null
ondragleave: null
ondragover: null
ondragstart: null
ondrop: null
onerror: null
onfocus: null
oninput: null
oninvalid: null
onkeydown: null
onkeypress: null
onkeyup: null
onload: null
onmousedown: null
onmousemove: null
onmouseout: null
onmouseover: null
onmouseup: null
onmousewheel: null
onpaste: null
onreset: null
onscroll: null
onsearch: null
onselect: null
onselectstart: null
onsubmit: null
outerHTML: "<textarea id="contentText">這是文字</textarea>"
outerText: ""
ownerDocument: HTMLDocument
parentElement: HTMLDivElement
parentNode: HTMLDivElement
placeholder: ""
prefix: null
previousElementSibling: null
previousSibling: Text
readOnly: false
required: false
rows: 2
scrollHeight: 36
scrollLeft: 0
scrollTop: 0
scrollWidth: 179
selectionEnd: 4
selectionStart: 4
style: CSSStyleDeclaration
tabIndex: 0
tagName: "TEXTAREA"
textContent: "這是文字"
textLength: 4
title: ""
type: "textarea"
validationMessage: ""
validity: ValidityState
value: "這是文字"
willValidate: true
__proto__: HTMLTextAreaElement
有四個元素(defaultValue、innerHTML、textContent、value)的內容都是"這是文字"
不過要是你把「這是文字」改成別的後,就會發現只有value發生變化……
當初看到innerHTML還以為就是這個的說……
結果竟然是value……
是說,這樣的話innerHTML和textContent是幹麼的?
defaultValue不是比較好懂嗎?(名稱的意味)
沒有留言:
張貼留言
小提示:留言時,可以使用粗體(<b>)、斜體(<i>)、超連結(<a href="網址"> </a>)。另外,以「名稱/網址」留言時,網址可以留空的。