js 动态增加 删除 html控件 单纯增加 可以用 innerHTML += "<input type='checkbox' />"; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在后台输出 respose.write("<script>根据ID给层加控件</script>") <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()" /> 试试看<!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="[email protected]" /> <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> http://www.cftea.com/c/2007/01/6344G8TRJHVCQ2PD.asp 就是楼上说的,自己写html当作字符串传到div里面 http://www.cnblogs.com/xiaotaomaomao/articles/986065.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="[email protected]" /> <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> 送你三本手册!DHTML参考手册http://download.csdn.net/source/308913样式表中文手册http://download.csdn.net/source/304124JScript语言参考http://download.csdn.net/source/308916 js根据php生成的js变量a=1表示有某种动作的权限,这样安全吗 关于JS的length问题 jquery问题 最新拖动层插件希望大家帮忙测试下 请大家推荐下好用的jquery插件 jsp javascript servlet javabean struts hibernate spring学习 帮忙解读一段js代码 IE FF下javascript的兼容问题,请高手帮忙! 这段代码怎么写 都写不好啊 Extjs4.0动态切换CSS的问题 就一小问题,怎么也搞不定,obj.focus()! 请教姓名的输入
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()" />
<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="[email protected]" />
<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>
<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="[email protected]" />
<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>
http://download.csdn.net/source/308913样式表中文手册
http://download.csdn.net/source/304124JScript语言参考
http://download.csdn.net/source/308916