<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>欢迎光顾我的小小潇潇网站!</title>
</head>
<script language="javascript" type="text/javascript">
function setAdd() {
var sel = document.getElementsByName("checkbox");
var ById = document.getElementById("setAdd");
var txt = ById.options[ById.selectedIndex].text; //获取下拉列表中的text值(显示值)
alert(txt);
if (sel[0].checked.toString() == "true") {
document.getElementById(txt).innerHTML += "<br /><input type='text'/>";
}
if (sel[1].checked.toString() == "true") {
document.getElementById(txt).innerHTML += "<br /><input type='checkbox'/>";
}
if (sel[2].checked.toString() == "true") {
document.getElementById(txt).innerHTML += "<br /> <select id='select'> <option>何乐为不为</option></select>";
}
if (sel[3].checked.toString() == "true") {
document.getElementById(txt).innerHTML += "<br /><input type='radio'/>";
}
}
</script>
<body >
<h2 >请完成以下添加任务:</h2>
<input id="cbo1" type="checkbox" name="checkbox" />
<input id="txt1" type="text" />
<br /><br />
<input id="cbo2" type="checkbox" name="checkbox" />
<input id="ckb1" type="checkbox" name="checkbox1" />
<br /><br />
<input id="cbo3" type="checkbox"name="checkbox" />
<select id="slt1">
<option></option>
</select>
<br /><br />
<input id="cbo4" type="checkbox"name="checkbox" />
<input id="rdo1" type="radio" name="radio1" />
<br /><br />
<input id="btn1" type="button" value="增加" onclick="setAdd()" />
<select id="setAdd" >
<option value="option1">a</option>
<option value="option2">b</option>
<option value="option3">c</option>
</select>
重点内容:
document.getElementById(txt).innerHTML += "<br /><input type='radio'/>";