0%

JavaScript笔记

onClick函数自定义参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
let onClick = function (dom, obj) {
if (dom.avtive) {
dom.avtive = false;
hide();
} else {
dom.avtive = true;
show(dom, obj)
}
}
let appendDomEvent = function (dom, obj) {
if (obj.event == 'click') {
dom.addEventListener('click', function () {
return onClick(dom, obj);
}, false)
}
if (obj.event == 'mouseouver') {
dom.addEventListener('mouseover', function () {
return onMouseOver(dom, obj);
}, false)
dom.addEventListener('mouseout', function () {
return onMouseOut(dom, obj);
}, false)
}
}

对象数据根据属性排序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
let objectArray = [
{name:'小红',subject:'math',grade:95},
{name:'小黄',subject:'math',grade:75},
{name:'小蓝',subject:'math',grade:84},
{name:'小# CCCCCC',subject:'math',grade:59},
]
function compare(T){
return function(a,b){
let v1 = a[T],v2 = b[T];
return v2 - v1;
}
}
objectArray.sort(compare('grade'));
console.log(objectArray);

一个前端连点器

1
2
3
4
5
6
var dom = document.getElementsByTagName("canvas")[0];
var oEvent;
oEvent = document.createEvent("MouseEvent");
oEvent.initMouseEvent("mousedown", true, false, document.defaultView, 0, 500, 500, 500,500);
function imitateClick() {dom.dispatchEvent(oEvent);}
setInterval(imitateClick,100);