javascript vkek - 操纵o DOM
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript vkek - 操纵o DOM相关的知识,希望对你有一定的参考价值。
function Vkek(){
// this.el será o elemento buscado apartir do Vkek.$()
}
Vkek.prototype = {
$: function(selector) {
if (typeof selector == 'string') {
this.el = (document.querySelectorAll(selector).length > 1) ? document.querySelectorAll(selector) : document.querySelector(selector);
} else {
this.el = selector;
}
return this;
},
addEvent: function(eventName, fn) {
this.el.addEventListener(eventName, fn);
return this;
},
click: function(fn){
this.el.addEventListener('click', fn);
return this;
},
load: function(fn){
window.addEventListener('load', fn);
return this;
},
html: function(html){
if (html == undefined) {
return this.el.innerHTML;
}
this.el.innerHTML = html;
return this;
},
each: function(fn){
for (i in this.el) {
fn(this.el[i], i);
}
}
}
function vkek(selector) {
_vkek = new Vkek();
if (selector != undefined){
_vkek.$(selector).el;
}
return _vkek;
}
以上是关于javascript vkek - 操纵o DOM的主要内容,如果未能解决你的问题,请参考以下文章
javascript DOM操纵和事件
javascript 操纵html(DOM和JQuery)
javascript js操纵数组
javascript Js - 操纵数组
JavaScript-14(操纵属性和window)
javascript 选择器操纵并向用户界面提供数据