在Javascript和Dhtmlx中创建一个复选框

时间:2016-06-20 14:15:21

标签: javascript html dhtmlx

我正在尝试创建一个基于javascript的复选框,但不知何故,我无法使其工作。我之前创建了一个问题,但不知何故无法将我的代码添加到评论中,因此提出了一个新问题。这就是我所做的:

function eXcell_includeDC(cell) {
    if (cell){            // the default pattern, just copy it
        this.cell = cell;
        this.grid = this.cell.parentNode.grid;
    }
    this.getValue = regExpGetValueCell;

    if (this.getValue = 'Y') {
        var myDiv = document.getElementById("includeDC");
        var checkbox = document.createElement("input"); 
        checkbox.setAttribute("type", "checkbox");
        checkbox.setAttribute("name", "dd");
        checkbox.setAttribute("value", "ff");
        checkbox.checked = true; 
        myDiv.appendChild(checkbox); 
        checkbox.checked = true;
    } else {
        var myDiv = document.getElementById("includeDC");
        var checkbox = document.createElement("input"); 
        checkbox.setAttribute("type", "checkbox");
        checkbox.setAttribute("name", "dd");
        checkbox.setAttribute("value", "ff");
        checkbox.checked = true; 
        myDiv.appendChild(checkbox); 
        checkbox.checked = false;
    }
    this.isDisabled = function() { 
        return true; 
    } 
    this.setValue=function(val) {
        // actual data processing may be placed here, for now we just set value as it is
        this.setCValue(val); 
    }
}
eXcell_includeDC.prototype = new eXcell;

1 个答案:

答案 0 :(得分:2)

您需要在setValue函数中创建需要在单元格中显示的所有html内容。 这是简化的例子:

function eXcell_includeDC(cell){ //the eXcell name is defined here
    if (cell){                // the default pattern, just copy it
        this.cell = cell;
        this.grid = this.cell.parentNode.grid;
    }
    this.edit = function(){}  //read-only cell doesn't have edit method
    // the cell is read-only, so it's always in the disabled state
    this.isDisabled = function(){ return true; }
    this.setValue=function(val){
        if (val=="Y")
        this.setCValue("<input type='checkbox' checked='checked/>",val);
        else
        this.setCValue("<input type='checkbox'/>",val);
    }
}
eXcell_includeDC.prototype = new eXcell;