修改于:2019-09-4
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<meta content="email=no" name="format-detection">
<title>test</title>
</head>
<body class="bgf">
<div id='content'></div>
</body>
<script>
//数组
let arr = Array.from({length:36},(k,v)=>k = {name:`第${v+1}疗程`,id:v+1})
//---回调地狱---start
function ok(){
return new Promise((resolve,reject)=>{
console.log("hi")
resolve("我是一");
})
}
ok().then((val)=>{
return new Promise((resolve,reject)=>{
setTimeout(()=>{
console.log(val+"2")
resolve(val);
},2000)
})
}).then((val)=>{
return new Promise((resolve,reject)=>{
setTimeout(()=>{
console.log(val+"3")
resolve(val);
},1000)
})
}).then(function(){
console.log("last")
})
//---回调地狱---ent
//---es7语法?俗称优雅版---start
let uzi=()=>{
return new Promise((resolve,reject)=>{
resolve(123);
})
}
let faker=async ()=>{
let a=0,b=0
await new Promise((resolve,reject)=>{
setTimeout(()=>{
console.log("1")
a=1;
resolve(1);//=确认,然后才继续执行
},2000)
})
await new Promise((resolve,reject)=>{
setTimeout(()=>{
b=2;
console.log("2")
resolve(2);
},1000)
})
let d=await uzi() //调用函数,可使用返回值
console.log(a+b)
console.log(d)
}
faker()
//---es7语法?俗称优雅版---end
//---函数链式调用---start
//this:谁调用就指向谁;如果遇到()=>{}:()=>{}中this继承于()=>{}外this
let foo =function (){ // 等价于 funtion foo(){}
this.name = '666' //this指向foo
this.set=(a)=>{
console.log("set:this=foo",this) //this继承于foo
return this
}
this.get=()=>{
console.log("get:this=foo",this.age,this) //this继承于foo
return this
}
}
foo.prototype.age = 12
foo.prototype.run = function(){
console.log('run:this=foo',this); //this指向foo
return this
}
foo.prototype.eat = ()=>{console.log('eat:this=window',this)}//this继承于window
let foo2=new foo() //构造函数之前不能是()=>函数,实例化后类似对象,才能像对象一样使用调用
foo2.set().get().run().eat()
//---函数链式调用---end
//获取div距离可视区域得信息(上下左右距离,自身宽高)start
document.getElementById('id').getBoundingClientRect()
//获取div距离可视区域得信息 end
//---对象链式调用---start
let oo={
name:'liu',
set(){
console.log(this.name,"this=oo",this)
return this
},
get(){ //get(){}等价于get:function(){}
console.log("this=oo",this)
return this
},
eat:function(){
console.log("this=oo",this)
return this
},
run:()=>{
console.log('this=window',this)
}
}
oo.set().get().eat().run()
//---对象链式调用---end
//fetch start
fetch('https://api.myjson.com/bins/74163').then(res=>res.json())
.then(res=>{
console.log(res)
})
.catch(err=>console.log(err))
//fetch end
//删除 start
let data = [{identity:1}]
data.map((item, index)=>{
if(item.identity != 1){
data.splice(index,1)
}
})
//删除 end
</script>
<script>
$(function(){
let html = ''
$.ajax({
type: 'GET',
url: 'http://xxxx/disease/getList',
headers: {
'Content-Type':"application/json; charset=utf-8"
},
data: {},
dataType: 'json',
success: function(data) { //data:[name:'11',value:[diseaseName:'77']]
if(data.code == 200) {
data.data.map(function(item,i){
let child
child = item.value.map(function(n,j){
let childs = ''
childs += '<tr>'+
'<td class="cent">'+(j+1)+'</td>'+
'<td class="cent" style="width: 100%;">'+n.diseaseName+'</td>'+
'</tr>'
return childs
})
html += '<h3 class="pd80">'+item.name+'</h3>'+
'<table border="0" cellspacing="0" cellpadding="0" class="tab">'+
'<tbody>'+
child.join('')+
'</tbody>'+
'</table>'
})
$('#content').append(html)
} else if(data.code == -1) {
//showTip(data.message, 3500);
} else {
//showTip("系统错误!" + data.message, 2000);
}
},
error: function(xhr, type) {
//showTip("获取失败!", 2000);
}
});
})
</script>
</html>