window.onload=function(){ getData(); } getData=function(){ $.ajax({ type: "get", url: "/selectall", data:{}, dataType: "json", success: function (data) { let tbody=$("#warp")[0]; tbody.innerHTML=""; for(var i in data){ let uid='"'+data[i].WbId+'"'; let td=""; let tr=""; td+=""+data[i].WbNumber+""+data[i].WbName+""+data[i].AddTime+""; tr=""+td+""; $(tbody).append(tr); } } }) } deleteData=function(id){ var r=confirm("是否确定删除此微博号?") if (r==true) { $.ajax({ type: "get", url: "/delete?id="+id, data:{}, dataType: "json", success: function (data) { if(data=="success"){ alert("删除成功!"); getData(); }else{ alert("删除失败!"); } } }) return; } } insert=function(){ let wbNum=$('.wbNum')[0].value; let wbName=$('.wbName')[0].value; $.ajax({ type: "get", url: "/insert?num="+wbNum+"&name="+wbName, data:{}, dataType: "json", success: function (data) { if(data=="success"){ alert("插入成功!"); show('.insertDiv'); getData(); }else{ alert("插入失败!"); } } }) } update=function(id){ show('.updateDiv'); let wbName=$('.newName')[0]; $.ajax({ type: "get", url: "/selectbyid?id="+id, data:{}, dataType: "json", success: function (data) { if(data.length!=0){ wbName.value=data[0].WbName; }else{ alert("查询失败!"); } } }) $(".update")[0].onclick=function(){ if(wbName.value==""){ alert("请填写要修改的微博名称!"); return; } $.ajax({ type: "get", url: "/update?id="+id+"&name="+wbName.value, data:{}, dataType: "json", success: function (data) { if(data=="success"){ alert("修改成功!"); show('.updateDiv'); getData(); }else{ alert("修改失败!"); } } }) }; } show=function(el){ let thisDiv=$(el)[0]; if(thisDiv.style.display=="" || thisDiv.style.display=="none"){ thisDiv.style.display="block"; }else{ thisDiv.style.display="none"; } }