DOJO复选框操作

 

代码
 1 /*
 2 必须引入dojo框架
 3 通常适用于一个容器中全选或是反选的操作
 4 同时检查是否有选中
 5 author:rnn
 6 */
 7 dojo.declare(
"CheckboxClass",
null,
{
    container: "tableId", /*所包含的容器ID*/
    checkboxes: null, /*所有的复选框集合,相当于一个nodeList*/
    count: 0, /*当前复选框个数*/
    selectedCount: 0, /*当前容易中复选框被选中的数目*/
    buttonType: 1, /*负责选择复选框的按钮类型 1表示自身在容器中 2表示在容器外*/
    constructor: function (container, buttonType) {
        this.container = container;
        this.buttonType = buttonType;
        this.checkboxes = dojo.filter(dojo.query("input", dojo.byId(this.container)), function (item) {
            return item.type == "checkbox";
        });
        this.count = this.checkboxes.length - 1;
        var index = 0;
        var currentIndex = 1;
        if (this.buttonType == 2) {
            this.count = this.count + 1;
            currentIndex = 0;
        }
        dojo.forEach(this.checkboxes, function (item) {
            if (index >= currentIndex) {
                dojo.connect(item, "click", ItemCheckboxClick);
            }
            index++;
        });
    }, /*构造函数,初始化一些数据*/
    Select: function (buttonId) {
        var isChecked = dojo.byId(buttonId).checked;
        if (isChecked) {
            dojo.forEach(this.checkboxes, function (item) {
                item.checked = true;
            });
            this.selectedCount = this.count;
        }
        else {
            dojo.forEach(this.checkboxes, function (item) {
                item.checked = false;
            });
            this.selectedCount = 0;
        }
    }, /*全选事件*/
    CheckSelectedCount: function () {
        if (this.selectedCount <= 0) {
            alert("未选中任何数据");
            return false;
        }
        return true;
    },
    SetSelectCount: function (type) {
        if (type == 1) {
            this.selectedCount = this.selectedCount + 1;
        }
        else {
            this.selectedCount = this.selectedCount - 1;
        }
    }
}
);

 

 

posted @ 2010-07-18 17:54  RoseNix  阅读(2663)  评论(0编辑  收藏  举报