1
특정 단어를 찾고 웹 브라우저에서 해당 단어를 강조 표시해야하는 작은 프로젝트를 수행하고 있습니다.웹 페이지에서 특정 단어를 찾으려면 어떻게합니까?
간단히 말해, 나는 다음과 같은 질문이 :
웹 페이지에서 각 단어에 태그 위치 (X, Y)이 있으면 궁금 해서요.
아무도 웹 페이지에서 작업하는 것에 대한 유용한 자습서의 지침을 알려줄 수 있습니까?
다음 코드를 구현하고 Google 크롬에서 웹 페이지와 상호 작용하고 싶습니다. 그것은 간단한 찾기 및 강조 기능입니다.
function doSearch(text) {
if (window.find && window.getSelection) {
document.designMode = "on";
var sel = window.getSelection();
sel.collapse(document.body, 0);
while (window.find(text)) {
document.getElementById("button").blur();
document.execCommand("HiliteColor", false, "lavender");
sel.collapseToEnd();
}
document.designMode = "off";
} else if (document.body.createTextRange) {
var textRange = document.body.createTextRange();
while (textRange.findText(text)) {
textRange.execCommand("BackColor", false, "lavender");
textRange.collapse(false);
}
}
}는 당신의 시간과 노력에 감사드립니다.
실제적인 JavaScript는 심각한 것 같습니다. 이것이 잘못된 방법 일뿐입니다. – Ian