- 前台调用
1 | var $ = function() { |
- 基础类
1 | function Base() { |
- 创建一个数组来获取一个节点和节点数组
1 | //Base.prototype.elements=[];这是是在类外面定义的,所以要把它放在类里面进行私有化 |
- 获取元素节点
1 | Base.prototype.getTagName = function(tag) { |
- 获取 Class 节点的信息
1 | Base.prototype.getClass = function(className) { |
- 获取某一个节点
1 | Base.prototype.getElement = function(num) { |
- 设置 CSS
1 | Base.prototype.css = function(attr, value) { |
- 设置 innerHTML
1 | Base.prototype.html = function(str) { |
- 添加 class 属性
1 | Base.prototype.addClass = function(className) { |
-删除 class 属性
1 | Base.prototype.removeClass = function(className) { |
- 添加 link 或 style 的 CSS 规则
1 | Base.prototype.addRule = function(num, selectorText, cssText, position) { |
- 删除 link 或 style 的 CSS 规则
1 | Base.prototype.removeRule = function(num, index) { |
- 设置点击事件
1 | Base.prototype.click = function(fn) { |
- 实际运行
1 | // JavaScript Document |