- 事件对象
var event = event || window.event;
// 事件的类型
console.log(event.type);
- 元素的坐标
clientX与clientY相对于当前页面且不包含滚动条距离 event.clientX
pageX/Y:相对于文档边缘,包含滚动条距离 event.pageY
- 阻止事件冒泡
event.stopPropagation();
- 阻止事件默认行为
e.preventDefault();
- 获取属性
getAttribute("属性的名字")也可以说自定义属性
- 设置属性
setObj1.onclick = function () {
in1.setAttribute("name", "password");
// in1.setAttribute("class", "");
in1.className = "";
// in1.setAttribute("style", "border:5px dotted pink");
in1.style.border = "5px dotted pink";
console.log(in1.getAttribute("name"));//password
}
- 移除属性
var removeObj = document.getElementById("remove");
removeObj.onclick = function () {
in1.removeAttribute("class");
div1.removeAttribute("name1");
}