<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<table>
<tr>
<td>
<input type="checkbox" name="checkbox1"/>white
<input type="checkbox" name="checkbox2"/>black
<input type="checkbox" name="checkbox3"/>red
<input type="checkbox" name="checkbox4"/>yellow
</td>
</tr>
<tr>
<td>
ColorName:<input type="text" name="color"/>
<input type="button" name="addCheckbox" value="addCheckbox"/>
</td>
</tr>
</table>
</body>
</html>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<table>
<tr>
<td>
<input type="checkbox" name="checkbox1"/>white
<input type="checkbox" name="checkbox2"/>black
<input type="checkbox" name="checkbox3"/>red
<input type="checkbox" name="checkbox4"/>yellow
</td>
</tr>
<tr>
<td>
ColorName:<input type="text" name="color"/>
<input type="button" name="addCheckbox" value="addCheckbox"/>
</td>
</tr>
</table>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN " "http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<title> Insert title here </title>
</head>
<body>
<table>
<tr>
<td id="checkColor">
<input type= "checkbox" name= "checkbox1 "/> white
<input type= "checkbox" name= "checkbox2 "/> black
<input type= "checkbox" name= "checkbox3 "/> red
<input type= "checkbox" name= "checkbox4 "/> yellow
</td>
</tr>
<tr>
<td>
ColorName: <input type="text" name= "color " id="color"/>
<input type= "button" name= "addCheckbox " value= "addCheckbox" onclick="addColor();"/>
<script type="text/javascript">
var addColor = function(){
var txtColor = document.getElementById("color");
if(!isEmpty(txtColor)){return;}
var td = document.getElementById("checkColor");
var ch = "<input type='checkbox' name='checkbox" + td.getElementsByTagName("input").length + "' /> " + txtColor.value;
td.innerHTML += ch;
} function isEmpty(txt){
var value = txt.value.replace(/(^\s*)|(\s*$)/g, "");
if(value.length == 0){
alert("请填写颜色名称!");
txt.focus();
return false;
}
return true;
}
</script>
</td>
</tr>
</table>
</body>
</html>