计算机编程

如何实现多次点击下拉菜单的值切换返回下拉按钮,现在只能返回第一次点击的值,之后点击就不能切换了按钮的值了divdivdivdivdivbuttontype="button"data-toggle="dropdown"aria-haspopup="true"aria-expanded="false"FilterbyYear/buttondivaria-labelledby="dropdownMenu1"/div/div/divdivdivbuttontype="button"data-toggle="dropdown"aria-haspopup="true"aria-expanded="false"FilterbyBrand/buttondivaria-labelledby="dropdownMenu1"/div/div/divdivdivbuttontype="button"data-toggle="dropdown"aria-haspopup="true"aria-expanded="false"FilterbyProductFamily/buttondivaria-labelledby="dropdownMenu1"/div/div/div/divahref="#"CLEAR/a/div/div$(document).ready(function(){$.ajax({method:"GET",url:"services/apis/laptops_getYears.php",dataType:"json",data:{}}).done(function(msg){msg.con.map(function(item,index){$("#year_sel").prepend("ahref='#'class='dropdown-item'data-value='"+item.Pro_Year+"'onclick='getBrand("+item.Pro_Year+")'"+item.Pro_Year+"/a");});});$(".remove_icon").click(function(event){if($(".product_item").length0){$(".product_item")[$(".product_item").length-1].remove();}});$("#year_sel").change(function(){getBrand();});$("#brand_sel").change(function(){getLine();});$("#line_sel").change(function(){getProduct();});})functiongetBrand(_year){year=_year;$.ajax({method:"GET",url:"services/apis/laptops_getBrand.php",dataType:"json",data:{year:_year}}).done(function(msg){$("#brand_sel").empty();msg.con.map(function(item,index){$("#brand_sel").prepend("ahref='#'class='dropdown-item'data-value='"+item.Brand+"'onclick='getLine(""+item.Brand+"")'"+item.Brand+"/a");});brand=msg.con[0].Brand;$("#year_btn").text(year);});}functiongetLine(brand){$.ajax({method:"GET",url:"services/apis/laptops_getLine.php",dataType:"json",data:{year:year,brand:brand}}).done(function(msg){$("#line_sel").empty();msg.con.map(function(item,index){$("#line_sel").prepend("ahref='#'class='dropdown-item'data-value='"+item.Pro_Line+"'onclick='getProduct(""+item.Pro_Line+"")'"+item.Pro_Line+"/a");});line=msg.con[0].Pro_Line;$("#brand_btn").text(brand);});}functiongetProduct(_line){$.ajax({method:"GET",url:"services/apis/laptops_getProducts.php",dataType:"json",data:{line:_line}}).done(function(msg){if($(".product_item").length=5){alert("Youcanonlycomparefourproductsatmost!");return};varproductSpec='ul';for(varlableinmsg.con[0]){productSpec+='li'+msg.con[0][lable]+'/li';};productSpec+='/ul';$("#product_details").append(productSpec);if($(".product_item").length=2){varmax_height=0;varlis=$(".product_item").find("li");$(lis).each((i,o)={max_height=Math.max($(o).index(),max_height)})varalls=[]for(vari=0;i=max_height;i++){vararr=[]$(".product_item").each((i2,o)={varli=$("li",o).eq(i)if(li.length){arr.push(li)}})alls.push(arr)}alls.forEach(item={vartheMax=Math.max.apply(null,item.map(li=li.height()))item.forEach(li={li.height(theMax)})})}$("#product_btn").text(line);});}

请大神帮忙实现Ajax返回表格数据功能现在实现了一部分功能需要实现如下功能:1.Filter后的结果返回到button按钮上2.页面加载时默认执行getHeader()3.每次筛选结束都按顺序添加ProductA/B/C/D!doctypehtmlhtmlxmlns=""lang="en"headmeta"Content-Type"content="text/html;charset=utf-8"/metaname="viewport"content="width=device-width,initial-scale=1,shrink-to-fit=no"titleLaptops/titlelinkrel="stylesheet"href=""stylebody{font-family:Arial;color:#666;}#content{width:1280px;margin:0auto;}#filter{margin:30px0;}#filter.container{position:relative;}#filter.container,#filter.container.row,#filter.container.row.col-md-4{margin:0;padding:0;}#filter.dropdown{display:inline-block;width:100%;}#filter.btn{border-radius:0;width:100%;height:70px;font-size:20px;background:#dc3545;color:#fff;border:1pxsolid#fff;}#filter.btn:hover{background:#c82333}#year_sel:after{margin-left:8.255em;}#brand_sel:after{margin-left:7.255em;}#line_sel:after{margin-left:3.255em;}.dropdown-menu{width:100%;}#line_sel{overflow-y:scroll;height:300px;}.remove_icon{position:absolute;right:-80px;top:0;line-height:70px;color:#000;text-decoration:underline;}/*产品*/#product_table{word-break:break-all;word-wrap:break-all;table-layout:fixed;}/style/headbody!--筛选内容--divdivdivdivdivbuttontype="button"data-toggle="dropdown"aria-haspopup="true"aria-expanded="false"FilterbyYear/buttondivaria-labelledby="dropdownMenu1"/div/div/divdivdivbuttontype="button"data-toggle="dropdown"aria-haspopup="true"aria-expanded="false"FilterbyBrand/buttondivaria-labelledby="dropdownMenu1"/div/div/divdivdivbuttontype="button"data-toggle="dropdown"aria-haspopup="true"aria-expanded="false"FilterbyProductFamily/buttondivaria-labelledby="dropdownMenu1"/div/div/div/divahref="#"CLEAR/a/div/divtabletheadtrthwidth="256px"Specs/ththwidth="256px"ProductA/ththwidth="256px"ProductB/ththwidth="256px"ProductC/ththwidth="256px"ProductD/th/tr/theadtbody/tbody/table!--筛选内容结束--/divscriptsrc=""/scriptscriptsrc=""/scriptscriptsrc=""/scriptscripttype="text/javascript"varyear='2018';varbrand='';varline='';$(document).ready(function(){$.ajax({method:"GET",url:"services/apis/getYears.php",dataType:"json",data:{}}).done(function(msg){msg.con.map(function(item,index){$("#year_sel").prepend("ahref='#'class='dropdown-item'data-value='"+item.Pro_Year+"'onclick='getBrand("+item.Pro_Year+")'"+item.Pro_Year+"/a");});//setTimeout(function(){//getBrand();//},0);getHeader();});$(".remove_icon").click(function(event){//console.log(event.currentTarget.getAttribute("data-id"));//$("#product_"+event.currentTarget.getAttribute("data-id")).remove();if($(".product_item").length0){$(".product_item")[$(".product_item").length-1].remove();}});$("#year_sel").change(function(){//console.log($("#year_sel").val());getBrand();});$("#brand_sel").change(function(){//console.log($("#year_sel").val());getLine();});$("#line_sel").change(function(){//console.log($("#year_sel").val());getProduct();});})functiongetBrand(_year){year=_year;$.ajax({method:"GET",url:"services/apis/getBrand.php",dataType:"json",data:{year:_year}}).done(function(msg){$("#brand_sel").empty();msg.con.map(function(item,index){$("#brand_sel").prepend("ahref='#'class='dropdown-item'data-value='"+item.Brand+"'onclick='getLine(""+item.Brand+"")'"+item.Brand+"/a");});brand=msg.con[0].Brand;setTimeout(function(){getLine(brand);},0);});}functiongetLine(brand){$.ajax({method:"GET",url:"services/apis/getLine.php",dataType:"json",data:{year:year,brand:brand}}).done(function(msg){$("#line_sel").empty();msg.con.map(function(item,index){$("#line_sel").prepend("ahref='#'class='dropdown-item'data-value='"+item.Pro_Line+"'onclick='getProduct(""+item.Pro_Line+"")'"+item.Pro_Line+"/a");});line=msg.con[0].Pro_Line;/*setTimeout(function(){getProduct(line);},0);*/});}functiongetHeader(_line){$.ajax({method:"GET",url:"services/apis/getProducts.php",dataType:"json",data:{line:_line}}).done(function(msg){msg.con.map(function(item,index){varspecTitle='';varrow=0;for(varlableinmsg.con[0]){specTitle+='trtd'+lable+'/td/tr';row++;};$("#product_details").append(specTitle);})})}functiongetProduct(_line){$.ajax({method:"GET",url:"services/apis/getProducts.php",dataType:"json",data:{line:_line}}).done(function(msg){/*$("#product_header").empty();$("#product_details").empty();varrow1=0;for(varlableinmsg.con[0]){$("#product_header").append('div'+lable+'/div');row1++;}*/if($(".product_item").length=4){console.log($(".product_item")[0]);$(".product_item")[0].remove();}$(".product_item").map(function(item,index){if(("product_"+msg.con[0]['Id'])==$(".product_item")[item].getAttribute("id")){$(".product_item")[item].remove();}});var_html='';varrow=0;for(varlableinmsg.con[0]){_html+='trtd'+lable+'/tdtd'+msg.con[0][lable]+'/td/tr';row++;};$("#product_details").append(_html);});}/script/body/html

其他新闻
  • 如何实现多次点击下拉菜单的值切换返回下拉按钮,现在只能返回第一次点击的值,之后点击就不能切换了按钮的值了divdivdivdivdivbuttontype="button"data-toggle="dropdown"aria-haspopup="true"aria-exp...
    2019-12-27
  • ##JS第一天####JaveScrip历史作者:BrendanEich版权归:Oracle所有最早诞生于1996年#####浏览器组成主要由两部分组成1,shell2,内核)#####chrome浏览器2008年Google发布最新浏览器,采用javeScript引擎...
    2019-12-27
  • 用vscode编辑器写js时,装上插件会有js函数方法全名提示回车后这个方法名字被补全但是并没有自动添加括号,别的编辑器都可以,期间我安照网上说的在setting.json里添加了typescript.......
    2019-12-27
友情链接

公司名称巴黎人电玩
版权所有:Copyright © 2015-2019 http://www.zhongqiangjy.com. 巴黎人电玩有限公司 版权所有

友情链接

Copyright © 2015-2019 http://www.zhongqiangjy.com. 巴黎人电玩有限公司 版权所有
公司地址http://www.zhongqiangjy.com