2015-11-20 127 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'; 
}