คำถามติดแท็ก nodevalue

6
nodeValue กับ innerHTML และ textContent วิธีการเลือก?
ฉันใช้ js ธรรมดาเพื่อแก้ไขข้อความภายในขององค์ประกอบป้ายกำกับและฉันไม่แน่ใจว่าเหตุใดฉันควรใช้ innerHTML หรือ nodeValue หรือ textContent ฉันไม่จำเป็นต้องสร้างโหนดใหม่หรือเปลี่ยนองค์ประกอบ HTML หรืออะไรเลย - เพียงแค่แทนที่ข้อความ นี่คือตัวอย่างของรหัส: var myLabel = document.getElementById("#someLabel"); myLabel.innerHTML = "Some new label text!"; // this works myLabel.firstChild.nodeValue = "Some new label text!"; // this also works. myLabel.textContent = "Some new label text!"; // this also works. ฉันดูแหล่งที่มา jQuery และใช้ …
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.