87,920
社区成员
发帖
与我相关
我的任务
分享
oRoot.replaceChild(newChild, oldChild)
。可以自己尝试下<script type="text/javascript">
function choose(obj) {
var oRoot = document.getElementById("sel_inp");
var oInp = document.getElementById("oInpId");
var oSel = document.getElementById("oSelId");
if (obj.checked) {
clear(oRoot, oSel);
creatInput(oRoot);
} else {
clear(oRoot, oInp);
createSelect(oRoot);
}
}
function clear(oRoot, oldChild) {
if (oldChild != null)
oRoot.removeChild(oldChild);
}
function creatInput(oRoot) {
var oInp = document.createElement("input");
oInp.setAttribute("id", "oInpId");
oInp.setAttribute("type", "text");
oInp.setAttribute("name", "sInput");
oRoot.appendChild(oInp);
}
function createSelect(oRoot) {
var oSel = document.createElement("select");
oSel.setAttribute("id", "oSelId");
oSel.options[0] = new Option("0", "0");
oSel.options[1] = new Option("1", "1");
oSel.options[2] = new Option("2", "2");
oRoot.appendChild(oSel);
}
</script>
请选择<input type="checkbox" name="ckb" onclick ="choose(this);">
<div id="sel_inp"></div>