다음과 같이 코드 코드를 복사하십시오.
<html>
<script language = "javaScript"type = "text/javaScript">
기능 test () {
// 요소를 만듭니다
var myelement = document.createElement ( "a");
// 생성 된 요소에 필요한 정보를 추가합니다
mylement.href = "http://www.baidu.com";
mylement.innertext = "Baidu에 연결";
myelement.id = "id1";
//myElement.style.top = "300px";
//myElement.style.left = "500px";
// myElement. style.position = "절대";
// 생성 된 요소를 신체 객체에 추가합니다
//document.body.appendChild (myelement);
// DIV에 요소를 추가합니다
document.getElementById ( "div1").
}
함수 test2 () {) {
// 요소를 삭제합니다
// 속성을 통해 새 요소의 부모 요소를 얻을 수도 있습니다.
//document.getElementById.
getElementById ( "div1")
}
</스크립트>
<body>
<입력 유형 = "버튼"onclight = "test ()"value = "하이퍼 링크를 활성화"/>
<input type = "button"onclight = "test2 ()"value = "dynamic 추가 요소 삭제"/>
<div id = "div1"style = "너비 : 200px; 높이 : 300px; 테두리 : 1px Solid Red">
div1
</div>
</body>
</html>