나는 최근에 다른 프로젝트를 사용했지만 InnerHTML을 호출 한 후에도 InnerHTML은 텍스트에 삽입 된 버튼이라는 것을 알았습니다 직접이지만 간접적으로 구현할 수 있습니다.
예 1 :이 예제는 달성 할 수없는 OnClick입니다.
다음과 같이 코드 코드를 복사하십시오.
<html>
<헤드>
<스크립트 연기>
기능 inscell (th)
var name = th.name;
var id = th.id;
if (name == "no") {{
id.innerhtml = "<input type = 'button'onclick = 'inscall (this)'value = 'online'
이름 = 'no'id = '1'> "";
} 또 다른 {
id.innerhtml = "<input type = 'button'onclick = 'inscall (this)'value = '오프라인'
이름 = '예'id = '1'> "" ";
}
</스크립트>
</head>
<body>
<br />
<span id = "msg">
<입력 유형 = "버튼"onclick = "INSCALL (this)"value = "오프라인"이름 = "예"id = "1">
</span>
</body>
</html>
위의 예는 버튼 또는 오프라인 이름을 기준으로 온라인인지 판단하는 것입니다 ~~~ 처음 클릭하면 유효하지 않습니다 ~~~~~~
현재 우리는 다음과 같이 변장을 실현할 수 있습니다.
다음과 같이 코드 코드를 복사하십시오.
<html>
<헤드>
<스크립트 연기>
기능 inscell (th)
{{
var name = th.name;
var id = th.id;
경고 (이름+"-"+id);
var span = document.getElementById (id);
if (name == "no") {{
span.innerhtml = "<input type = 'button'value = 'offline'>";
span.name = "예";
} 또 다른 {
span.innerhtml = "<input type = 'button'value = 'Go Online'>";
span.name = "아니오";
}
}
</스크립트>
</head>
<body>
<br />
<span id = "1"onclick = "inscell (this)"name = "no">
<입력 유형 = "버튼"value = "온라인">
</span>
</body>
</html>