Creating a Checkbox in Javascript and Dhtmlx

荒凉一梦 提交于 2019-12-24 08:23:13

问题


I am trying to create a javascript based checkbox and the but somehow I am not able to make it work. I created a question earlier but somehow not able to add my code to the comments, hence making a new question. This is what i did:

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:


You need to create all your html content that needed to be displayed in your cell in the setValue function. Here is the simplified example:

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;


来源:https://stackoverflow.com/questions/37924810/creating-a-checkbox-in-javascript-and-dhtmlx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!