18521344213
010-22445632
artskin@163.com
阿沐2018
进入这个页面,先打开Console控制台
var num=0,timer=null;
function say_hello(num){
console.log("这是"+num)
}
function onStart(){
//定时器
timer = setInterval(function(){
say_hello(num)
},1000)
}
function selectNumber(e){
num = e.options[e.selectedIndex].value;
console.log("set",num)
}
function onStop(){
clearInterval(timer)
}
var parent = document.getElementsByTagName("ul")[0],
child = parent.children, //childNodes 包含空格和换行
addLi = document.getElementsByTagName("span")[0];
console.log(fe.typePro(parent))
console.log(fe.typePro(child))
addLi.onclick = function(){
var newLi = document.createElement("li");
newLi.innerHTML = child.length+":新建行";
parent.appendChild(newLi);
}
document.body.addEventListener("click",function(e){
console.log("click-body");
},false); //false:冒泡 | true:捕获
parent.addEventListener("click",function(e){
console.log("click-parent");
//事件委托:ie/chrome为srcElement,ff为target
e = e || window.event;
let target = e.target || e.srcElement;
if(target.nodeName.toLowerCase() == 'li'){
console.log("click-child",target.innerHTML);
}
console.log(target.children);
},false);
//for(let i=1;i < child.length; i++){
// child[i].addEventListener("click",function(e){
// console.log("click-child",e);
// },false);
//}
//addEventListener 可以绑定多个事件,并分别执行
//onclick= ""绑定事件后边的会覆盖前边的事件
//通用的事件绑定方法:ie8及以下用attachEvent
function addEvent(el, evnt, fun){
return el.attachEvent ? el.attachEvent('on'+evnt, fun) : el.addEventListener(evnt, fun, false);
}
function uploadFile(obj){
var fileData = new FormData();
fileData.append("file",obj[0].files[0]);
console.log(fileData);
$.ajax({
url : 'http://106.14.7.135:8081/upload/image',
type : 'POST',
dataType:"JSON",
processData : false, //告诉jQ不要去处理发送的数据
contentType : false, //告诉jQ不要设置Content-Type请求头
data : fileData,
success:function(data){
console.log(data)
}
})
}
uploadFile($("#file"))
var arr = [0,1,2,3];
for(let i=0; i < arr.length; i++){
setTimeout(function(){
console.log("case1",i)
},i*1000)
}
var items = [1,'a','b',9,3,8,5,6,7,4,2,0];
var lists = [0,'a',1,10,20,3,40,5,60,6];
var sameArr=[];
var diffArr=[];
for(let i=0; i < items.length; i++){
if(lists.indexOf(items[i]) != -1){
sameArr.push(items[i]);
}
if(!lists.includes(items[i])){
diffArr.push(items[i])
}
}
console.log("sameArr",sameArr);
console.log("diffArr",diffArr);
const arr = [2,4,5,6,7,2,5]
const arr2 = [[2,4],[2,5],[3,6],[4,7],[2,5],[2,4]];
//console.log(arr2)
const unique = [... new Set(arr)];
const unique2 = [... new Set(arr2)];
function uniquePlus(arr){
let arrNew =[];
for(let i=0; i < arr.length; i++){
arrNew.push(arr[i].toString());
//console.log(!arrNew.includes(arr.indexOf(arr[i])));
//console.log(arrNew)
}
let indexs = [];
arrNew.map((item,index)=>{
// console.log(item,index);
if(arrNew.includes(arrNew.indexOf(arrNew[index]))){
indexs.push(index)
console.log(index,"重复第"+index+"项",arr[index]);
}else{
arrNew.push(arr.indexOf(arr[index]))
}
})
indexs.map((item,index)=>{
console.log(item)
arr.splice(item,1);alert("1")
})
//arr.splice
return arr
}
console.log(arr2)
let nn = uniquePlus(arr2);
console.log("去重后的数字:",nn)
Set.__proto__.constructor = function(arr){
}
var arr = ['c',3,1,4,'v',2,5];
function quick(arr){
if(arr.length<=1){
return arr;
}
var left = [];
var right = [];
var base = arr[0];
for(var i=1;i < arr.length; i++){
// 判决条件
if(arr[i]>base){
right.push(arr[i]);
}else {
left.push(arr[i])
}
}
return quick(left).concat(base,quick(right));
}
console.log(quick(arr));
var animal = {a:10,b:20,c:30}
var people = animal;
console.log("people",people);
people.a = 100;
console.log("people:",people)
console.log("animal:",animal);
console.log("----------")
var dog = JSON.parse(JSON.stringify(animal))
dog.b = 200
console.log("animal:",animal);
console.log("dog",dog);
let obj ={
name:'luci',
age:30
}
let newObj = Object.assign(obj,{
sex:'男',
age:20
});
let newObj2 = JSON.parse(JSON.stringify(obj))
newObj2.age = 40;
newObj2.sex = "女"
console.log(obj)
console.log(newObj)
console.log(newObj2)
function feibo(len) {
var fbarr = [1,1];
for(let n =2;n < len;n++){
fbarr[n] = fbarr[n-1]+fbarr[n-2];
}
return fbarr;
}
console.log(feibo(30));
var a="001";
console.log("a",a);
setTimeout(function(){
console.log("setTimeout.a",a)
},0);
var b="002";
console.log("b",b);
//Promise
new Promise(function executor(resolve) {
console.log(10);
for( var i=0 ; i < 5 ; i++ ) {
console.log("Promise.for",i)
i == 4 && resolve();
}
console.log(20);
}).then(function() {
console.log("Promise.then",5);
});
var c="003";
console.log("c",c);
var arr = ['a','b','c','d'];
Array.prototype.qq = 10;
for(let i=0;i < arr.length;i++){
if(i == 3) break;
console.log(i,arr[i]);
}
console.log("-----分割线2-----")
arr.forEach(function(val){
console.log(val);//无法 break
});
console.log("-----分割线3-----")
for(let i in arr){
//for in循环会把某个类型的原型(prototype)中方法与属性给遍历出来
console.log(arr[i])
}
console.log("-----分割线4-----")
let obj = {aa:1,bb:2,cc:3,dd:4};
Object.prototype.score = 97;
console.log(obj);
for(let key in obj){
console.log(key,obj[key])
}
console.log("-----分割线5-----")
//for ... of 遍历数组
for(let item of arr){
console.log(item)
}
var hi ="hello world"
//for ... of 遍历字符串
for(let item of hi){
//console.log(item)
}
//for ... of 还可以遍历map/set/dom
/**
* 获取指定个数的随机数,范围[2,32]
* @param {number} n:需要的整数个数
* @return {array} 返回随机数数组,个数为n
*/
function isPositiveInteger(s){//是否为正整数
var re = /^[0-9]+$/ ;
return re.test(s)
}
function rangeRandom(min,max){
return Math.floor(Math.random()*(max-min+1)+min);
}
function fn(n){
//变量声明
var min =2,max=32;
//参数校验
if(typeof n === 'number' && isPositiveInteger(n)){
var arr = [];
for(let i=0;i < n;i++){
var num = rangeRandom(2,32);
arr.push(num);
}
console.log(arr)
return arr;
}else{
return []
}
}
fn(5);
var arr = ['12',12,false,undefined,null,[1,2,3],{},function(){}];
for(let i=0;i < arr.length;i++){
console.log(isType(arr[i]))
}
function isType(obj){
if(obj == null){
return String( obj )
}else{
let str = Object.prototype.toString.call(obj).split(" ").pop();
return str.substring(0,str.length -1);
}
}
function class2type(i,name){
}
//console.log(isType(1),isType('1'),isType(function(){}),isType([]))
var name = 'the window'
var obj ={
name:'my obj',
getnamefun:function(){
//var self = this;
return function(){
return this.name;
}
}
}
//console.log(this.name);
//console.log(obj.getnamefun()());
console.log(typeof Infinity ==='number');
var str = new String('im string');
var str2 = 'im string';
console.log(typeof str);
console.log(typeof str2);
console.log((function(){return typeof arguments})())
function f(){};
var o={};
console.log(f.__proto__)
console.log(f.__proto__.__proto__)
console.log(o.__proto__)
console.log(f.prototype)
console.log(o.prototype)
function dds(){
var div = document.getElementById('test');
div.circularReference = div;
div.lotsOfData=new Array(1000).join("*");
}
dds()
function add(a, b) {
var realLen = arguments.length;
console.log("realLen:", arguments.length);
console.log(arguments[0]);
console.log(arguments[1]);
console.log(arguments[2]);
console.log(arguments[3]);
var len = add.length;
console.log("len:", add.length);
if (realLen == len) {
console.log('实参 = 形参个数');
} else {
console.log('实参 ≠ 形参个数');
}
};
add(1,2,3);
var sum = 0.1+0.2;
console.log(sum == 0.3) //false
function add(num1, num2) {
const num1Digits = (num1.toString().split('.')[1] || '').length;
const num2Digits = (num2.toString().split('.')[1] || '').length;
const baseNum = Math.pow(10, Math.max(num1Digits, num2Digits));
return (num1 * baseNum + num2 * baseNum) / baseNum;
}
console.log(add(0.1,0.2) == 0.3) //true