动态拼接html

一、有时需要将后台的数据显示出来,或者两种数据之间的动态联动(被联动的)这就需要动态的

1、举个实例

			function opencast(crelation){
				DWREngine.setAsync(false);
				dwrSrv.queryCancelCost(crelation,function(obj){
					$("#itemtableDiv").empty();//#<span style="font-family: Arial, Helvetica, sans-serif;">itemtableDiv 是要拼接的位置</span>
					var text=obj;
					var $table=$("#itemtableDiv");
					if(text!=null){
						var $thead='<table style="width: 100%;"><thead><tr>';
							$thead+='<th class="col1">序号</th><th class="col2">商品名称</th><th class="col3">数量</th><th class="col4">单价</th><th class="col5">单位</th>';
							$thead+='</tr></thead>';
						var $tbody='<tbody>';
						for(var i=0;i<text.length;i++){
							$tbody+='<tr>';
							$tbody+='<td class="col1">'+(i+1)+'</td>';
							$tbody+='<td class="col2">'+text[i].goods_name+'</td>';
							$tbody+='<td class="col3">'+text[i].count+'</td>';
							$tbody+='<td class="col4">'+text[i].price+'</td>';
							$tbody+='<td class="col5">'+text[i].unit+'</td>';
							$tbody+='</tr>'
						}
						$tbody+='</tbody></table>';
						$table.append($thead+$tbody);
					}
					$('#chooseModal').modal('show');
				})
			}

2、动态拼接下拉框

			function choiceBoss(hotel_id,job){
 				DWREngine.setAsync(false);
				dwrSrv.queryBoss(hotel_id,job,function(obj){
					var text=obj;
					$select=$("#boss_id");
					if(text!=null){
						$("#boss_id").attr("disabled",false); 
						$("#boss_id").empty(); 
						$("#boss_id").css("background","");
						var $option='';
							$option+='<option value="">全部</option>';
						for(var i=0;i<text.length;i++){
							 $option+='<option value='+text[i].id+'>'+text[i].name+'</option>';
						}
						$select.append($option);
					}else{
						$("#boss_id").empty(); 
						$("#boss_id").attr("disabled","disabled"); 
						$("#boss_id").css("background","#E0DFDF");
					}
				})
			}

这就是动态拼接html (用的jquery的方法)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值