2015-11-20 93 views
1

然后dhtmlxLayout单元格被折叠,我怎样才能使标题文本为中心对齐,以及如何使整个标签单元格处于折叠状态时可点击? 我有下面的代码:dhtmlxlyout标题文本对齐中心

dhxLayout = new dhtmlXLayoutObject(document.body, "3U"); 
dhxLayout.cells('a').setText('<div id="a">Text to Center</div>'); 
dhxLayout.cells('b').setText('<div id="b">Text to Center</div>'); 
dhxLayout.attachEvent("onDblClick", function (itemId){ 
    //how can I do it here? 
} 

回答

2

你可以尝试下一个方法:

var h, panName; 
function doOnLoad() { 
    dhxLayout = new dhtmlXLayoutObject(document.body, "3U"); 
    //put cell text in a div 
    dhxLayout.cells('a').setText('<div id="a">Text to Center</div>'); 
    dhxLayout.cells('b').setText('<div id="b">Text to Center</div>'); 
    //use double click to collapse/expand cell 
    dhxLayout.attachEvent("onDblClick", function (itemId){ 
     if (dhxLayout.cells(itemId).isCollapsed() == false){ 
      dhxLayout.cells(itemId).collapse(); 
     } 
     else dhxLayout.cells(itemId).expand(); 
    }); 
    //center the label 
    dhxLayout.attachEvent("onCollapse", function(name){ 
     panName = name; 
     recount(panName) 
    }); 
    dhxLayout.attachEvent("onPanelResizeFinish", function(){ 
     recount(panName) 
    }); 
    dhxLayout.attachEvent("onResizeFinish", function(){ 
     recount(panName) 
    }); 
} 
function recount(panName){ 
    h = dhxLayout.cells("a").getHeight(); 
    document.getElementById(panName).style.width = (h-20)+"px"; 
    document.getElementById(panName).style.textAlign = 'center'; 
}