问题
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