Home > Backend Development > PHP Tutorial > 选择下拉后,如何只显示一种内容

选择下拉后,如何只显示一种内容

WBOY
Release: 2016-06-20 12:43:26
Original
1288 people have browsed it

比如,当我选择日志时,会在下面显示一列内容,但是当我再次选择周述职时,周述职的内容会接着日志的内容显示在下面,这样就导致了选择几次就显示几次内容,而我想要的是,选择日志就只显示日志的内容,选择周述职时,自动删除之前显示的日志内容,只显示周述职的内容。。。。
<script> <br />function getNewRow() <br />{ <br /> var type = $("#type").val(); <br /> <br /> $.get("/oa/oa_api.php?act=get_oa_type",{ <br /> type:type, <br /> async:false, <br /> rand: Math.random() <br /> },function(data){ <br /> if(data.status.code=="1") <br /> { <br /> //成功 <br /> for(var i=0;i<data.record.length;i++) <br /> { <br /> var cg_id = data.record[i].cg_id; <br /> var nr = data.record[i].nr; <br /> var trHtml; <br /> trHtml = '<tr id="tr_' + cg_id + '">'; <br /> trHtml += '<td width="5%" height="60"> '; <br /> trHtml += '<td width="30%" align="right">' + nr + ''; <br /> trHtml += '<td><textarea name="sznr_' + cg_id + '" id="sznr_' + cg_id + '" cols="60" rows="5">'; <br /> trHtml += ''; <br /> $("#tb_chuku").append(trHtml); <br /> } <br /> } <br /> },"json"); <br />} <br /></script>


                        
                          
                          
                          
                        
  类型:


回复讨论(解决方案)

//删掉$("#tb_chuku").append(trHtml);//在循环外面改成$("#tb_chuku").html(trHtml);
Copy after login
Copy after login
Copy after login

//成功$("#tb_chuku tr:gt(0)").remove(); //删除第一行以后的行for(var i=0;i<data.record.length;i++){......
Copy after login
Copy after login
Copy after login

//成功$("#tb_chuku tr:gt(0)").remove(); //删除第一行以后的行for(var i=0;i<data.record.length;i++){......
Copy after login
Copy after login
Copy after login


那如果选择日志后不止一行怎么办?

什么是 第一行以后?

//成功$("#tb_chuku tr:gt(0)").remove(); //删除第一行以后的行for(var i=0;i<data.record.length;i++){......
Copy after login
Copy after login
Copy after login


加了这句以后,不显示了

//删掉$("#tb_chuku").append(trHtml);//在循环外面改成$("#tb_chuku").html(trHtml);
Copy after login
Copy after login
Copy after login


当选择日志后显示出来内容后,再选周述职时,如果周述职没有内容,则原来日志的内容还在那里

//删掉$("#tb_chuku").append(trHtml);//在循环外面改成$("#tb_chuku").html(trHtml);
Copy after login
Copy after login
Copy after login


而且只显示最后一条内容
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template