<html>
<head>
<script type=
"text/javascript"
>
window.onload =
function
() {
var
aBtn = document.createElement(
"input"
);
var
bBtn = document.createElement(
"input"
);
var
cBtn = document.createElement(
"input"
);
aBtn.type =
"button"
;
aBtn.value =
"按钮A"
;
aBtn.onclick = copyBtn;
bBtn.type =
"button"
;
bBtn.value =
"按钮B"
;
bBtn.onclick = copyBtn;
cBtn.type =
"button"
;
cBtn.value =
"按钮C"
;
cBtn.onclick = clearCopyBtn;
document.body.appendChild(aBtn);
document.body.appendChild(bBtn);
document.body.appendChild(cBtn);
};
function
copyBtn() {
var
btn = document.createElement(
"input"
);
btn.type =
"button"
;
btn.value =
this
.value;
btn.isCopy =
true
;
btn.onclick = copyBtn;
document.body.appendChild(btn);
}
function
clearCopyBtn() {
var
btns = document.getElementsByTagName(
"input"
);
var
length = btns.length;
for
(
var
i = length - 1; i >= 0; i--) {
if
(btns[i].isCopy) {
document.body.removeChild(btns[i]);
}
}
}
</script>
</head>
<body>
</body>
</html>