jquery动态往table添加tr

<table cellpadding=10 id="tabId" >
		<tr>
		    <td>
			 <form:label class="control-label" path="projectName">
				 <spring:message code="project.name" />
			</form:label>
		   </td>
		  <td colspan="4">
			<form:input style="width:450px;" path="projectName" readonly="true"/> 
			 <form:hidden  path="projectNumber" /> 
		 </td>
		</tr>
</table>



<div>
	<button class="btn btn-info btn-green" id="addYear">
		<i class="icon-ok bigger-110"></i> 增一年
	</button>
</div>	



<script type="text/javascript">
	  var i = 0;
	  
	  $(function(){			
		  $("#addYear").click(function(){		
			  var nowYear = $("#nowYear").val(); 
			  if(i == 0) {
				 i++;
				 var nextYear = nowYear + 1;
				 $str = '';
				 $str += "<tr>";
				 $str += "      <td>";
				 $str += "          <form:label class=\"control-label\" path=\"plan.nextPlanCompleteWork\">";
				 $str += "             <spring:message code=\"plan.planCompleteWork\" />";
				 $str += "          </form:label>";
				 $str += "      </td>";
				 $str += "      <td>";
				 $str += "          <form:input path=\"plan.nextPlanCompleteWork\"  />";
				 $str += "          <site:required /><form-extension:errors path=\"plan.nextPlanCompleteWork\" cssClass=\"error\" />";
			     $str += "      </td>";
			     $str += "      <td>";
				 $str += "          <form:label class=\"control-label\" path=\"plan.nextPlanCompleteFinancial\" >";
				 $str += "             <spring:message code=\"plan.planCompleteFinancial\" />";
				 $str += "          </form:label>";
				 $str += "      </td>";
				 $str += "      <td>";
				 $str += "          <form:input path=\"plan.nextPlanCompleteFinancial\"  />";
				 $str += "          <site:required /><form-extension:errors path=\"plan.nextPlanCompleteFinancial\" cssClass=\"error\" />";
			     $str += "      </td>";
			     $str += "</tr>";
			     
			     $("#tabId").append($str);// 添加输入的值到tabId末尾	
			     
			  } else if(i == 1) {
				 i++;
				 var afterYear = nowYear + 2;
				 $str = '';
				 $str += "<tr>";
				 $str += "      <td>";
				 $str += "          <form:label class=\"control-label\" path=\"plan.afterPlanCompleteWork\">";
				 $str += "             <spring:message code=\"plan.planCompleteWork\" />";
				 $str += "          </form:label>";
				 $str += "      </td>";
				 $str += "      <td>";
				 $str += "          <form:input path=\"plan.afterPlanCompleteWork\"  />";
				 $str += "          <site:required /><form-extension:errors path=\"plan.afterPlanCompleteWork\" cssClass=\"error\" />";
			     $str += "      </td>";
			     $str += "      <td>";
				 $str += "          <form:label class=\"control-label\" path=\"plan.afterPlanCompleteFinancial\" >";
				 $str += "             <spring:message code=\"plan.planCompleteFinancial\" />";
				 $str += "          </form:label>";
				 $str += "      </td>";
				 $str += "      <td>";
				 $str += "          <form:input path=\"plan.afterPlanCompleteFinancial\"  />";
				 $str += "          <site:required /><form-extension:errors path=\"plan.afterPlanCompleteFinancial\" cssClass=\"error\" />";
			     $str += "      </td>";
			     $str += "</tr>"; 
			     
                 $("#tabId").append($str);// 添加输入的值到tabId末尾			
			  }
		  }); 		 
	  });// 加载结束
    </script>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值