Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jquery怎样去除重复数据啊,大神 #2

Open
pingtang121212 opened this issue Aug 22, 2017 · 1 comment
Open

jquery怎样去除重复数据啊,大神 #2

pingtang121212 opened this issue Aug 22, 2017 · 1 comment

Comments

@pingtang121212
Copy link

当数据库里的数据只有一个时,怎样让jquery只显示一条数据,而不是追加
这是:table.html

<title>无标题文档</title> <style> .tab{border:2px solid #09C; border-collapse:collapse;width:100%; } .trr{border:2px solid #09C; border-collapse:collapse; } table .trr th{border:2px solid #09C; font-size:14px; font-family:'黑体';background-color:#CCC; height:14px } table .trr td{border:2px solid #09C; font-size:14px; font-family:'黑体'; height:10px ; text-align:center} </style> <script type="text/javascript" src="http://keleyi.com/keleyi/pmedia/jquery/jquery-1.10.2.min.js"></script> <script type="text/javascript" src="table.js"> </script>
楼号 房间号 支路数 故障类型 采集值 预警状态 故障发生时间
楼号 房间号 支路数 故障类型 采集值 预警状态 故障发生时间
这是:table.js: $(window).ready( function () { setInterval("kkk()", 2000); }); function kkk(){ $.ajax({ type:'POST', url:'tabgle.php', data:{ buildnum: $('#diva .tab .trr #1').val(), roomnum: $('#diva .tab .trr #2').val(), branchnum: $('#diva .tab .trr #3').val(), codetype: $('#diva .tab .trr #4').val(), getnum: $('#diva .tab .trr #5').val(), warning: $('#diva .tab .trr #6').val(), codetime: $('#diva .tab .trr #7').val(), watchpoint: $('#spa').val() }, dataType:"json", success:function(response,status,xhr){
			 //response=JSON.parse(response);
			  $('#spa').html(response[7]);
		 
			 if(response[1]==3){
				  response[5]="蓝色预警";
				   $('#divb .tab .trr #1').html(response[0]+"楼");
			 $('#divb .tab .trr #2').html(response[1]+"号");
			 $('#divb .tab .trr #3').html(response[2]);
			 $('#divb .tab .trr #4').html(response[3]);
			 $('#divb .tab .trr #5').html(response[4]+"K");
			 $('#divb .tab .trr #6').html(response[5]);
			 $('#divb .tab .trr #7').html(response[6]);
			  html="";
			  for(var i=0;i<7;i++){
			 html="<tr class='trr'><td>"+(response[0]+"楼")+"</td><td>"+(response[1]+"号")+"</td><td>"+response[2]+"</td><td>"+response[3]+"</td><td>"+(response[4]+"K")+"</td><td>"+response[5]+"</td><td>"+response[6]+"</td></tr>";
			  	
			  }
			  $('#divb #tab').append(html);
				  }else if(response[1]==4){
					  response[5]="橙色预警";
				   $('#divb .tab .trr #1').html(response[0]+"楼");
			 $('#divb .tab .trr #2').html(response[1]+"号");
			 $('#divb .tab .trr #3').html(response[2]);
			 $('#divb .tab .trr #4').html(response[3]);
			 $('#divb .tab .trr #5').html(response[4]+"K");
			 $('#divb .tab .trr #6').html(response[5]);
			 $('#divb .tab .trr #7').html(response[6]);
			  html="";
			  for(var i=0;i<7;i++){
			 html="<tr class='trr'><td>"+(response[0]+"楼")+"</td><td>"+(response[1]+"号")+"</td><td>"+response[2]+"</td><td>"+response[3]+"</td><td>"+(response[4]+"K")+"</td><td>"+response[5]+"</td><td>"+response[6]+"</td></tr>";
			  	
			  }
			  $('#divb #tab').append(html);
					  
					  }else{
					  
			 $('#diva .tab .trr #1').html(response[0]+"楼");
			 $('#diva .tab .trr #2').html(response[1]+"号");
			 $('#diva .tab .trr #3').html(response[2]);
			 $('#diva .tab .trr #4').html(response[3]);
			 $('#diva .tab .trr #5').html(response[4]+"K");
			 $('#diva .tab .trr #6').html(response[5]);
			 $('#diva .tab .trr #7').html(response[6]);
			 html="";
			  for(var i=0;i<7;i++){
			 html="<tr class='trr'><td>"+(response[0]+"楼")+"</td><td>"+(response[1]+"号")+"</td><td>"+response[2]+"</td><td>"+response[3]+"</td><td>"+(response[4]+"K")+"</td><td>"+response[5]+"</td><td>"+response[6]+"</td></tr>";
			  	
			  }
			  $('#diva #tab').append(html);						  } ;
			/* $('#div1 .tab .trr #1').html(response[0]+"楼");
			 $('#div1 .tab .trr #2').html(response[1]+"号");
			 $('#div1 .tab .trr #3').html(response[2]);
			 $('#div1 .tab .trr #4').html(response[3]);
			 $('#div1 .tab .trr #5').html(response[4]+"K");
			 $('#div1 .tab .trr #6').html(response[5]);
			 $('#div1 .tab .trr #7').html(response[6]);
			 $('#div2 .tab .trr #1').html(response[0]+"楼");
			 $('#div2 .tab .trr #2').html(response[1]+"号");
			 $('#div2 .tab .trr #3').html(response[2]);
			 $('#div2 .tab .trr #4').html(response[3]);
			 $('#div2 .tab .trr #5').html(response[4]+"K");
			 $('#div2 .tab .trr #6').html(response[5]);
			 $('#div2 .tab .trr #7').html(response[6]);*/

			  //alert($('tr[id=11] td[id=5]').html());//调试
			  //$('#div1 .tab tr[id=12] td[id=1]').html(response[0]);
			  
			 /* html="";
			  for(var i=0;i<7;i++){
			 html="<tr class='trr'><td>"+(response[0]+"楼")+"</td><td>"+(response[1]+"号")+"</td><td>"+response[2]+"</td><td>"+response[3]+"</td><td>"+(response[4]+"K")+"</td><td>"+response[5]+"</td><td>"+response[6]+"</td></tr>";
			  	
			  }
			  $('#div1 #tab').append(html);
			  $('#div2 #tab').append(html);	*/			
			   // alert($('.tab tr').length);
			  $('#diva .tab tr').each(function(index) {
                if(index>3000){
				$(this).hide;			  }
            });
			 $('#divb .tab tr').each(function(index) {
                if(index>3000){
				$(this).hide;			  }
            });
			
			$('#num1').html($('#diva .trr').length-1);
			$('#num2').html(($('#divb .trr').length-1));
		 	 	}
				
			}) 
};

$(document).ready(function(){
$("tr:odd").css("background-color","#B2E0FF");
});
这是:

如果解决了,麻烦通知我一下;qq是:1539286010

@HerbertKarajan
Copy link
Owner

@pingtang121212 我给你一个思路:你首先去获取当前数据库是否是一条,如果是,就显示,不追加。否则。。。。。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants