Ciao.
Scusa per il pezzettone di codice
(che tra l'altro va bene !) il problema non era
in js ma nel css :
codice di esempio (+ corto
)
Codice PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
* {
margin:0px;
padding:0px
}
a:link, a:visited,a:hover,a:active {
text-decoration : none;
color:#62AC24;
font-weight:700;
}
body {
text-align:center;
background-color:#EDF6D9;
color:#28780A
}
div#container {
margin: 0 auto;
width:940px;
border:1px solid #77B608;
text-align:left
}
div#header {
margin-bottom:20px;
border-bottom:1px solid #77B608;
}
div#header h1 {
line-height:70px;
text-align:center;
}
div#navigation {
float: left;
width: 150px
}
div#content {
height: auto !important;
height: 200px;
min-height: 200px;
margin-left: 150px
}
div#footer {
clear: left;
border-top:1px solid #77B608;
line-height:30px;
}
div#footer h3 {
text-align:center
}
/* MAIN MENU */
h4#panel {
margin-left:5px;
}
div#navigation ul {
width: 155px;
margin-left:5px;
list-style-type: none
}
div#navigation ul li a {
display: block;
width: 150px;
text-decoration:none;
background-color:#EDF6D9;
color:#62AC24;
font-weight:700;
}
div#navigation ul li a.active {
display: block;
width: 150px;
text-decoration:none;
background-color:#EDF6D9;
color:#AC6A24;
font-weight:700;
}
/* DOM */
ul#userDetails {
list-style-type: none
}
span.errors {
font-size:12px;
color:#FF0000
}
form {
width:400px;
}
form label {
color:#28780A;
}
form input {
width:160px;
padding-left:5px;
border:1px solid #fff
}
form input#bottom {
width:160px;
margin-top:5px;
border:1px solid #fff;
/*background-color:#77B608;*/
color:#FFFFFF;
}
/*table {
table-layout: fixed;
width:770px;
margin:0px 10px;
}*/
tr.former {
background-color:#FFE0CA
}
tr.latter {
background-color:#DFF3C0
}
</style>
<script language="JavaScript" type="text/JavaScript">
function getTable(cs,cp)
{
var table = document.createElement('table');
table.setAttribute('cellspacing',cs);
table.setAttribute('cellpadding',cp);
return table;
}
function getHeadTable(h,w)
{
if(h.length!=w.length){return;}
var tHead = document.createElement('thead');
var hTr = document.createElement('tr');
for (var i = 0; i < h.length; i++)
{
var th = document.createElement('th');
th.setAttribute('width',w[i]);
th.appendChild(document.createTextNode(h[i]));
hTr.appendChild(th);
}
tHead.appendChild(hTr);
return tHead;
}
function getFootTable(v)
{
var tFoot = document.createElement('tfoot');
var fTr = document.createElement('tr');
for (var i = 0; i < v.length; i++)
{
var td = document.createElement('td');
td.appendChild(document.createTextNode(v[i]));
fTr.appendChild(td);
}
tFoot.appendChild(fTr);
return tFoot;
}
function getBodyTable()
{
var tBody = document.createElement('tbody');
return tBody;
}
function test()
{
var content = document.getElementById('content');
if(!content){return;}
h = ['N°','Username','Email','Join Date','Last Login','Delete'];
w = ['3%','17%','36%','20%','20%','4%'];
var table = getTable('0','0');
var tHead = getHeadTable(h,w);
var tBody = getBodyTable();
table.appendChild(tHead);
table.appendChild(tBody);
content.appendChild(table);
alert(content.firstChild.tagName);
alert(table.parentNode.tagName);
}
window.onload = function()
{
test();
}
</script>
</head>
<div id="container">
<div id="header">
<h1>User Manager</h1>
</div>
<div id="navigation">
<h4 id="panel">Control Panel</h4>
<ul>
[*][url="index.php"]Home[/url]
[*][url="index.php"]Edit Password[/url]
[*][url="index.php"]View Profile[/url]
[*][url="index.php"]Users List[/url]
[/list]
</div>
<div id="content"></div>
<div id="footer"><h3>By Whisher</h3></div>
</div>
</html>
Il problema è qui
/*table {
table-layout: fixed;
width:770px;
margin:0px 10px;
}*/
Se togli il commento avrai l'errore.
Ok posso definire width direttamente
nella tabella ma mi piacerebbe capire
cosa c'è che non va !