帮忙修改一个函数。
function CreateGrid(itemHeight, totalWidth, itemNum, bgColor, borderColor, itemText)
{
var div_grid = 0;
var div_subitem = 0;
var strSubInnerHTML = "";
var itemWidth = totalWidth/itemNum-1; //减1是因为要设置右边框
div_grid = document.createElement("div");
div_subitem = document.createElement("div");
div_subitem.style.cssText = "width:"+itemWidth+"px;height:"+itemHeight+";margin:auto;position:relative;background-color:"+bgColor+";border-right:solid 1px "+borderColor+";float:left;";
for(var i = 0; i < itemNum; i++)
{
div_subitem.index = i;
if(itemText != null)
{
div_subitem.innerText = itemText[i];
}
strSubInnerHTML += div_subitem.outerHTML;
}
div_grid.innerHTML = strSubInnerHTML;
return div_grid;
}
要把上面的这个函数改成不用innerText 和outerHTML,只用innerHTML 来实现怎么改?前提是只能用div不能用table的形式。
------解决方案--------------------
试看....
function CreateGrid(itemHeight, totalWidth, itemNum, bgColor, borderColor, itemText)
{
var div_grid = 0;
var div_subitem = 0;
var strSubInnerHTML = "";
var itemWidth = totalWidth/itemNum-1; //减1是因为要设置右边框
div_grid = document.createElement("div");
div_subitem = document.createElement("div");
div_subitem.style.cssText = "width:"+itemWidth+"px;height:"+itemHeight+";margin:auto;position:relative;background-color:"+bgColor+";border-right:solid 1px "+borderColor+";float:left;";
for(var i = 0; i < itemNum; i++)
{
div_subitem.index = i;
if(itemText != null)
{
//div_subitem.innerText = itemText[i];
var tn=document.createTextNode(itemText);
div_subitem.appendChild(tn);
}
//strSubInnerHTML += div_subitem.outerHTML;
}
//div_grid.innerHTML = strSubInnerHTML;
div_grid.appendChild(div_subitem);
return div_grid;
}