Test

修改于: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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

刘斩仙的笔记本

富贵险中求

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值