<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>haha</title>
</head>
<body>
<ul class="list">
<li>aa<a href="#">删除</a></li>
<li>bb<a href="#">删除</a></li>
<li>cc<a href="#">删除</a></li>
<li>dd<a href="#">删除</a></li>
<li>ee<a href="#">删除</a></li>
</ul>
<script>
var ul = document.getElementsByClassName("list")[0];
ul.onclick = function(event){
var obj = event.srcElement||event.target;
var li = obj.parentNode;
ul.removeChild(li);
}
</script>
</body>
</html>
<!doctype html>
<html>
<head>
<style type="text/css">
.circle {
width: 100px;
height: 100px;
border-radius: 50px;
background-color: red;
position: relative;
animation-iteration-count: infinite;
animation-duration: 3s;
animation-name: scroll;
}
@keyframes scroll {
from {
left: 0;
}
50% {
left: 100px;
}
to {
left: 0;
}
}
</style>
</head>
<body>
<div class="circle"></div>
</body>
</html>
function getcookie(objname){//获取指定名称的cookie的值
var arrstr = document.cookie.split("; ");
for(var i = 0;i < arrstr.length;i ++){
var temp = arrstr[i].split("=");
if(temp[0] == objname) return unescape(temp[1]);
}
}
var EventEmitter = function () {
this.events = {}; //保存事务,存储结构为{'eventName1':[{listener:function触发的函数, time:触发的次数}], 'eventName2':[],}
};
/*获取所有的事务*/
EventEmitter.prototype.getEvents = function () {
return this.events || (this.events = {});
}
/*获取某个实践的所有触发函数*/
EventEmitter.prototype.getListeners = function (evt) {
var events = this.getEvents();
return events[evt] || (events[evt] = []);
};
/**
注册实践触发函数
evet:事件名称
listener:事件监听函数
time:可选,选择可以触发的次数,-1表示无数次,默认为-1
**/
EventEmitter.prototype.on = function (evt, listener, time) {
time = typeof (time) == 'number' ? time : -1;
time = time >= -1 ? time : -1;
var listeners = this.getListeners(evt);
var listenerWrapper = {
listener: listener,
time: time,
};
listeners.push(listenerWrapper);
return this;
};
EventEmitter.prototype.once = function (evt, listener) {
return this.on(evt, listener, 0);
};
/*移除事件的所有监听函数*/
EventEmitter.prototype.off = function (evt) {
var events = this.getEvents();
events[evt] = [];
};
/**
触发事件
**/
EventEmitter.prototype.trigger = function (evt, args) {
var listeners = this.getListeners(evt);
for (var i = 0; i < listeners.length; i++) {
var listener = listeners[i];
if (listener.time != -1) {
listener.time--;
}
if (listener.time == 0) {
this.removeListener(evt, listener.listener); //可以同步或异步执行
}
listener.listener.apply(this, args || []);
}
};