<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery之div添加取消及内容替换demo</title>
<script type="text/javascript" src="./jquery.js" ></script>
<script language="javascript">
$(document).ready( function(){
$("#Objall").hide();
$("#school").removeAttr("checked");//取消选中
});
function show(){
if($("#school").attr("checked")==true){
$("#Objall").show();
}else{
$("#Objall").hide();
}
}
var i =1;
function addshow(){
i = i+1;
var aa=$("#Objtable").html();
aa = "<div id= Objtable"+i+" >" + aa + "</div>";
aa=aa.replace('1',i);
$("#divObj").append(aa);
}
function cancel(){
if(i == 1){
$("#Objall").hide();
$("#school").removeAttr("checked");//取消选中
}else{
$("#Objtable"+i+"").remove();
i = i-1;
}
}
</script>
</head>
<body>
<h3>增加培训机构</h3>
<form action="#" method="get">
<table>
<tr>
<td align="right">培训机构名:</td>
<td><input type="text" name="school_name" /></td>
</tr>
<tr>
<td align="right">培训科目:</td>
<td><input type="text" name="school_subject" /></td>
</tr>
<tr>
<td align="right">培训对象:</td>
<td><input type="text" name="school_trainee" /></td>
</tr>
<tr>
<td align="right">地 区:</td>
<td><input type="text" name="area" /></td>
</tr>
<tr>
<td align="right">地 址:</td>
<td><input type="text" name="address" /></td>
</tr>
<tr>
<td align="right">交通情况:</td>
<td><input type="text" name="traffic" /></td>
</tr>
<tr>
<td align="right">联系人:</td>
<td><input type="text" name="linkman" /></td>
</tr>
<tr>
<td align="right">联系方式:</td>
<td><input type="text" name="contact" /></td>
</tr>
<tr>
<td align="right">营业执照:</td>
<td><input type="file" name="license" /></td>
</tr>
<tr>
<td align="right">校区介绍:</td>
<td><input type="textarea" cols=16 rows=6 name="school_describ" /></td>
</tr>
</table>
<br/>
<input type="checkbox" id="school" onclick="show()"/>如果你有分支机构,请填写。
<div id="Objall">
<div id="divObj">
<div id="Objtable">
<table>
<tr>
<td>分支机构1名:</td>
<td><input type="text" name="department_name[]" /></td>
</tr>
<tr>
<td>地区:</td>
<td><input type="text" name="department_area[]" /></td>
</tr>
<tr>
<td>地址:</td>
<td><input type="text" name="department_address[]" /></td>
</tr>
<tr>
<td>联系人:</td>
<td><input type="text" name="department_linkman[]" /></td>
</tr>
<tr>
<td>联系方式:</td>
<td><input type="text" name="department_contact[]" /></td>
</tr>
<tr>
<td colspan="2"><hr color="gray"></td>
</tr>
</table>
</div>
</div>
<a href="#" onclick="addshow()">再添加一个分支机构</a>
<a href="#" onclick="cancel()">取消添加</a>
</div >
<br/>
<input type="submit" value="确认"/><input type="button" value="取消" onclick="history.go(-1);"/>
</form>
</body>
</html>