XML DOM replaceData() 메서드
❮ 텍스트 개체
예시
다음 코드 조각은 " books.xml "을 xmlDoc에 로드하고 첫 번째 <title> 요소의 텍스트 노드에서 처음 8자를 "Easy"로 바꿉니다.
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var x = xmlDoc.getElementsByTagName("title")[0].childNodes[0];
document.getElementById("demo").innerHTML =
x.nodeValue;
x.replaceData(0,8, "Easy");
document.getElementById("demo").innerHTML +=
"<br>" +
x.nodeValue;
}
산출:
Everyday Italian
Easy Italian
정의 및 사용
replaceData() 메서드는 텍스트 노드의 데이터를 바꿉니다.
통사론
replaceData(start,length,string)
Parameter | Description |
---|---|
start | Required. Specifies where to begin replacing characters. Start value starts at zero |
length | Required. Specifies how many characters to replace |
string | Required. Specifies the string to insert |
❮ 텍스트 개체