<img src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/174119533356720.jpg" class="lazy" alt="Re-Write a Layer's Content with Javascript "> <p>Modifying webpage content dynamically without server requests is a frequent task for web developers. Layers offer a straightforward solution. This article demonstrates a reusable JavaScript function for updating layer content across major browsers (Netscape 4/6/7 and IE 4/5/6).</p> <p>Here's the core function:</p> ```javascript function WriteLayer(ID, parentID, sText) { if (document.layers) { let oLayer; if (parentID) { oLayer = eval('document.' + parentID + '.document.' + ID + '.document'); } else { oLayer = document.layers[ID].document; } oLayer.open(); oLayer.write(sText); oLayer.close(); } else if (parseInt(navigator.appVersion) >= 5 && navigator.appName == "Netscape") { document.getElementById(ID).innerHTML = sText; } else if (document.all) { document.all[ID].innerHTML = sText; } }
함수는 세 가지 인수를 취합니다 :
: 레이어의 ID (예 : "Mylayer")
: Netscape 4의 중첩 레이어에 대한 상위 계층의 ID. 네 베스트 레이어에ID
를 사용하는 반면 Netscape 6/7과 IE는 각각 parentID
현재 시간을 표시 할 버튼이있는 예제 :
null
중첩 레이어 (예를 들어, 다른 레이어 내의 레이어)의 경우 sText
에 대한 질문이 자주 묻습니다
JavaScript 컨텐츠 계층은 무엇입니까?
JavaScript에서 컨텐츠 레이어는 웹 페이지 컨텐츠의 계층 적 구성을 나타냅니다 : HTML 구조, CSS 스타일링 및 JavaScript 인터랙티브. 이러한 계층을 이해하면 코드 구성, 디버깅 및 효율성이 향상됩니다
컨텐츠 계층에 대해 더 많이 배우는 방법?
?
document.layers
document.getElementById
document.all
층으로 작업 할 때 일반적인 실수?
위 내용은 JavaScript로 레이어 컨텐츠를 다시 작성하십시오의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!