87,997
社区成员




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="Gao YiXiang" />
<meta name="email" content="yixianggao@126.com" />
<meta name="keywords" content="javascript dhtml dom" />
<meta name="description" content="I love web development." />
</head>
<body>
<input type="button" id="btnAddChk" value="Add CheckBox" />
<input type="button" id="btnRemoveChk" value="Remove Selected CheckBoxes" />
<div id="divContainer"></div>
</body>
<script type="text/javascript">
<!--
function $(sId)
{
return document.getElementById(sId);
}
var oCon = $("divContainer");
var iIndex = 0;
$("btnAddChk").onclick = function()
{
var oSection = document.createElement("div");
oCon.appendChild(oSection);
var oChk = document.createElement("input");
oChk.type = "checkbox";
oChk.id = "chk" + iIndex++;
oSection.appendChild(oChk);
var oLab = document.createElement("label");
oLab.htmlFor = oChk.id;
oLab.innerHTML = "label for " + oLab.htmlFor;
oSection.appendChild(oLab);
};
$("btnRemoveChk").onclick = function()
{
var bIsSelected = false;
var cChk = oCon.getElementsByTagName("input");
for (var i=cChk.length-1; i>=0; i--)
{
if (cChk[i].type.toLowerCase() == "checkbox" && cChk[i].checked)
{
bIsSelected = true;
oCon.removeChild(cChk[i].parentNode);
}
}
if (!bIsSelected)
{
alert("Please selected!");
}
}
//-->
</script>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="Gao YiXiang" />
<meta name="email" content="yixianggao@126.com" />
<meta name="keywords" content="javascript dhtml dom" />
<meta name="description" content="I love web development." />
</head>
<body>
<input type="button" id="btnAddChk" value="Add CheckBox" />
<div id="divContainer"></div>
</body>
<script type="text/javascript">
<!--
function $(sId)
{
return document.getElementById(sId);
}
var oCon = $("divContainer");
var iCounter = 0;
$("btnAddChk").onclick = function()
{
var oChk = document.createElement("input");
oChk.type = "checkbox";
oChk.id = "chk" + iCounter++;
oCon.appendChild(oChk);
var oLab = document.createElement("label");
oLab.htmlFor = oChk.id;
oLab.innerHTML = "label for " + oLab.htmlFor;
oCon.appendChild(oLab);
var oBr = document.createElement("br");
oCon.appendChild(oBr);
};
//-->
</script>
</html>
<script>
function hehe()
{
document.getElementById("div1").innerHTML="<span>hehe</span><input type='checkbox' name='hehe' />"
}
</script>
<div id="div1">
</div>
<input type="button" value="Add" onclick="hehe()" />