js獲取元素的innerText屬性為什么為空


看這樣一段內容:

<div id="ii" style="visibility:hidden">
    <a style="cursor: hand">{0}/{1}</a>
    <a style="cursor: hand">[首頁]</a>
    <a style="cursor: hand">[上頁]</a>
    <a style="cursor: hand">[下頁]</a>
    <a style="cursor: hand">[末頁]</a>
    <input style="width: 20px; height: 16px" id="Text1">
</div>
<script>
    var a = document.getElementById("ii").children[0];
    document.write(a.innerHTML + " + " + a.innerText);
</script>

在ff瀏覽器因為沒有支持innerText所以自然無法使用,chrome瀏覽器中a標簽的innerText屬性是沒有辦法獲取的,原因就是它的父級div將visibility設置為了hidden(而display:none並不影響chrome的innerText取值),那么在IE瀏覽器中仍然是可以獲取的!!!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM