日期:2014-05-16 浏览次数:20511 次
<html>
<script type="text/javascript">
function processor(){
var echkbox = null;
var addhere=document.getElementById("div");
echkbox=document.createElement("input");
echkbox.setAttribute("type","checkbox");
echkbox.setAttribute("id","checkbox");
echkbox.setAttribute("value","蔬菜");
echkbox.onclick = addValue;
addhere.appendChild(echkbox);
addhere.appendChild(document.createTextNode("蔬菜"));
}
function addValue(){
var value = "";
var len = document.all.checkbox.length;
//显示当前checkbox的个数
window.alert(len)
for(var i=0;i<len;i++){
if(document.all.checkbox[i].checked == true){
value = value + document.all.checkbox[i].value +",";
}
}
//给text文本框赋值
document.getElementById("text").value = value;
}
</script>
<body>
<center>
种类:<input type="text" id="text" />
<div id="div" >
</div>
<input type="button" value="增加" onclick="processor();">
</center>
</body>
</html>
<html>
<script type="text/javascript">
function processor(){
var echkbox = null;
var addhere=document.getElementById("div");