獲取:
①innerHTML :屬性設置或返回該標簽內的HTML。也就是從對象的起始位置到終止位置的全部內容,包括Html標簽。
②outerHTML:屬性設置或返回該標簽及標簽內的HTML。也就是從對象的該標簽起始到終止位置的全部內容,包括Html標簽。
如果要輸出不含HTML標簽的內容,可以使用innerHTML取得包含HTML標簽的內容后,再用正則表達式去除HTML標簽,
③inneText:從起始位置到終止位置的內容,但它去除html標簽。(只能在IE和chrome下使用)
④outerText 設置(包括標簽)或獲取(不包括標簽)對象的文本
⑤value:屬性可設置或返回密碼域的默認值。獲取文本框的值
html:
<div id='test'>您輸入的值是:<span id="aqi-display">尚無錄入</span></div>
js:
<script>
var test = e('#test')
console.log('innerHTML', test.innerHTML)
console.log('outerHTML', test.outerHTML)
console.log('innerText', test.innerText)
console.log('outerText', test.outerText)
console.log('value', test.value)
</script>
區別
設置:
備注:innerText 和outerText 在讀取得時候是一樣的,只是在設置的時候outerText 會連帶標簽一起替換成目標文本
同理 innerHTML, outerHTML. 只不過它們操作的不是text而是HTML.
原來
點擊change_innerText
點擊change_outerText
Paste_Image.png
Paste_Image.png