XML DOM splitText() 메서드
❮ 텍스트 개체
예시
다음 코드 조각은 " books.xml "을 xmlDoc에 로드하고 첫 번째 단어 다음에 텍스트 노드를 분할합니다.
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];
var y = x.splitText(9);
document.getElementById("demo").innerHTML
=
x.nodeValue + "<br>" + y.nodeValue;
}
산출:
Everyday
Italian
정의 및 사용
splitText() 메서드는 텍스트 노드를 지정된 오프셋에서 두 개의 노드로 분할합니다.
이 함수는 오프셋 뒤에 텍스트가 포함된 노드를 반환합니다.
오프셋 앞의 텍스트는 원래 텍스트 노드에 남아 있습니다.
통사론
splitText(offset)
Parameter | Description |
---|---|
offset | Required. Specifies where to split the text node. Offset value starts at zero |
❮ 텍스트 개체