/ / encapsulation typeof function what (val) {var ty = typeof (val), toStr = Object. The prototype. The toString, res = {‘ [Object Array] ‘: ‘array’, ‘[object Object]’: ‘object’, ‘[object Number]’: ‘object number’, ‘[object String]’: ‘object string’, ‘[object Boolean]’: ‘object boolean’ }; if (val === null) { return ‘null’ } else if (ty === ‘object’) { var ko = toStr.call(val); return res[ko]; } return ty; }

Function getScroll () {if (window.pagexoffset) {return {left: window.pagexoffset, top: window.pageYOffset } } else { return { left: document.body.scrollLeft + document.documentElement.scrollLeft, top: document.body.scrollTop + document.documentElement.scrollTop } } }

Function getViewPort () {if (window.innerheight) {return {widthX: window.innerwidth, heightY: window.innerHeight, } } else {

	if (document.compatMode === 'BackCompat') {
		return {

			widthX: document.body.clientWidth,
			heightY: document.body.clientHeight
		}
	} else {
		return {
			widthX: document.documentElement.clientWidth,
			heightY: document.documentElement.clientHeight
		}
	}
}
Copy the code

} function getComstyle(ele, pro) { if (window.getComputedStyle) { if (pro) { return window.getComputedStyle(ele, null)[pro]; } else { return window.getComputedStyle(ele, null); } } else { if (pro) { return ele.currentStyle(ele, null)[pro]; } else { return ele.currentStyle(ele, null); }}} / / deep copy function deepclone (origin, target) {var target = target | | {}, toStr = Object. The prototype. The toString, arrType = ‘[object Array]’; for (var key in origin) { if (origin.hasOwnProperty(key)) { if (typeof(origin[key]) === ‘object’ && origin[key] ! == null) { toStr.call(origin[key]) === arrType ? target[key] = [] : target[key] = {}; deepclone(origin[key], target[key]) } else { target[key] = origin[key]; }}

Function addEvent(ele,type,fn){if(ele. AddEventlistener){ele. AddEventlistener (type,fn,false)}else if(ele.attachEvent){ ele.attachEvent("on"+type,function(){ fn.call(ele) }) }else{ ele["on"+type]=fn; }} / / encapsulation cancel bubbling event function stopEvent (e) {var e = e | | window. The event; if(e.stopPropagation){ e.stopPropagation() }else{ e.cancelBubble=true; } } // function getscrollPage(){ if(window.pageXOffset){ return { left:window.pageXOffset, top:window.pageYOffset } }else{ return { left:document.body.scrollLeft + document.documentElement.scrollLeft, top:document.body.scrollTop + document.documentElement.scrollTop } } } function pagePos(e) { var sLeft=getscrollPage().left, sTop=getscrollPage().top, cLeft=document.documentElement.clientLeft || 0, cTop=document.documentElement.clientTop || 0; return { X:e.clientX + sLeft -cLeft, Y:e.clientY + sTop -cTop } } //promiso function getpromose(fpath) { var promise = new Promise(function(resolve, reject) { fs.readFile(fpath, 'utf-8', (err, dataser) => { if (err) return reject(err) resolve(dataset) }) }) return promise } vat go = getpromose('./1.text'); go.then(function(data) { console.log(data) }, function(err) { console.log(err) } ) $(function(){ $('#btn').on('click',function(){ $.ajax({ url:'hu.json', type:'get', dataType:"json", success:function(data){ console.log(data) } }) function getDate(type, url) { var xhr = new XMLHttpRequest(); xhr.open(type, url, true); xhr.send(); xhr.onreadystatechange = function() { if (xhr.readyState === 4 && xhr.status === 200) { console.log(JSON.parse(xhr.responseText)) } } } function ajax(option) { var xhr = new XMLHttpRequest(), type = option.type || "GET", asy = option.asy || true, data = option.data || {}, url = option.url, str = '? '; for (var key in data) { str += key + '=' + data[key] + "&" } str = str.slice(0, str.length - 1); url += str; xhr.onreadystatechange = function() { if (xhr.readyState === 4 && xhr.status === 200) { var json = Json.parse (xhr.responseText) option.success(JSON)} else {option.err(" get data failed ")}} xhr.open(type, url, asy); xhr.send(); } ajax({ type: 'GET', data: { "pageNum": 1, "pageSize": 10 }, url: "Http://132.232.94.151:3000/api/film/getList", success: function (data) {for (var I = 0; i < data.films.length; i++) { var li = '<li>' + data.films[i].name + '</li>' list.insertAdjacentHTML('beforeend', li); } } }) function ajax(option) { var xhr = new XMLHttpRequest(), type = option.type || "GET", asy = option.asy || true, data = option.data || {}, url = option.url, str = '? '; for (var key in data) { str += key + '=' + data[key] + "&" } str = str.slice(0, str.length - 1); url += str; xhr.onreadystatechange = function() { if (xhr.readyState === 4 && xhr.status === 200) { var json = Json.parse (xhr.responseText) option.success(JSON)} else {option.err(" get data failed ")}} xhr.open(type, url, asy); xhr.send(); } ajax({ type: 'GET', data: { "pageNum": 1, "pageSize": 10 }, url: "Http://132.232.94.151:3000/api/film/getList", success: function (data) {for (var I = 0; i < data.films.length; i++) { var li = '<li>' + data.films[i].name + '</li>' list.insertAdjacentHTML('beforeend', li); }}})Copy the code