⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkbox.lib.js

📁 asp的bbs程序
💻 JS
字号:
/*
  By Hangring
  #2008.02.26#
  ---
  use list:
  > global.lib.js
  > node.lib.js
  > events.lib.js
  > node.lib.js
  > css.lib.js
  ---
  复选框
  ---
  包含样式:
  <link rel="stylesheet" href="css/checkbox.lib.css" type="text/css" />
*/
function CheckBox (name, value) {
    this.container = null;
    // the checkbox object
    this.checkbox = null;
    // checkbox's name
    this.name = name || 'checkbox_' + Math.random();
    // checkbox's value
    this.value = value || '';
    // view text
    this.text = '';
    // checked or not
    this.checked = false;

    this.css = {
        container:'check-box',
        icon:'icon',
        icon_checked:'icon-checked',
        icon_nonchecked:'icon-nonchecked'
    };
}

CheckBox.prototype.Init = function () {
};

CheckBox.prototype.Create = function () {
    var self = this;

    var container = this.container = oNode.CreateNode('a');
    CSS.AddClass(container, this.css.container);
    container.href = '#';
    var checkbox = this.checkbox = oNode.CreateNode('input');
    checkbox.type = 'checkbox';
    oNode.AddNode(checkbox, container);
    checkbox.name = this.name;
    checkbox.value = this.value;
    var icon = oNode.CreateNode('span');
    oNode.AddNode(icon, container);
    CSS.AddClass(icon, this.css.icon);
    if (this.text) {
        var label = oNode.CreateNode('label');
        oNode.AddNode(label, container);
        oNode.AddNode('\x20' + this.text, label);
    }

    Events.AttachEvent(container, 'click', function (e) {
        if (self.checked) {
            CSS.ReplaceClass(icon, self.css.icon_checked, self.css.icon_nonchecked);
        }
        else {
            CSS.ReplaceClass(icon, self.css.icon_nonchecked, self.css.icon_checked);
        }
        self.checked = !self.checked;
        self.checkbox.checked = self.checked;
        self._Change();
        Events.CancelAll(e);
    });
    Events.AttachEvent(container, 'mouseover', function (e, th) {
        self._MouseOver(e, th || this);
    });
    Events.AttachEvent(container, 'mouseout', function (e, th) {
        self._MouseOut(e, th || this);
    });

    return container;
};

CheckBox.prototype._MouseOver = function (e /* window.event|MouseEvent:Object */, th /* :HTMLElement */) {
    this.MouseOver(e, th);
};
CheckBox.prototype.MouseOver = function (e /* window.event|MouseEvent:Object */, th /* :HTMLElement */) {
};

CheckBox.prototype._MouseOut = function (e /* window.event|MouseEvent:Object */, th /* :HTMLElement */) {
    this.MouseOut(e, th);
};
CheckBox.prototype.MouseOut = function (e /* window.event|MouseEvent:Object */, th /* :HTMLElement */) {
};

CheckBox.prototype._Change = function () {
    this.Change();
};
CheckBox.prototype.Change = function () {
    //alert(this.checked);
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -