bylo by možno mi poradit, proč se mi u rozšířeného javascriptového kódu nevykresluje HTML tabulka?
Zde je skript:
Kód: Vybrat vše
<script type="text/javascript">
function sachovnice() {
sachovnice = new Array(8);
sachovnice[0] = new Array(8);
sachovnice[0][0] = 0;
sachovnice[0][1] = 0;
sachovnice[0][2] = 0;
sachovnice[0][3] = 0;
sachovnice[0][4] = 0;
sachovnice[0][5] = 0;
sachovnice[0][6] = 0;
sachovnice[0][7] = 0;
sachovnice[1] = new Array(8);
sachovnice[1][0] = 0;
sachovnice[1][1] = 0;
sachovnice[1][2] = 0;
sachovnice[1][3] = 0;
sachovnice[1][4] = 0;
sachovnice[1][5] = 0;
sachovnice[1][6] = 0;
sachovnice[1][7] = 0;
sachovnice[2] = new Array(8);
sachovnice[2][0] = 0;
sachovnice[2][1] = 0;
sachovnice[2][2] = 0;
sachovnice[2][3] = 0;
sachovnice[2][4] = 0;
sachovnice[2][5] = 0;
sachovnice[2][6] = 0;
sachovnice[2][7] = 0;
sachovnice[3] = new Array(8);
sachovnice[3][0] = 0;
sachovnice[3][1] = 0;
sachovnice[3][2] = 0;
sachovnice[3][3] = 0;
sachovnice[3][4] = 0;
sachovnice[3][5] = 0;
sachovnice[3][6] = 0;
sachovnice[3][7] = 0;
sachovnice[0] = new Array(8);
sachovnice[4][0] = 0;
sachovnice[4][1] = 0;
sachovnice[4][2] = 0;
sachovnice[4][3] = 0;
sachovnice[4][4] = 0;
sachovnice[4][5] = 0;
sachovnice[4][6] = 0;
sachovnice[4][7] = 0;
sachovnice[5] = new Array(8);
sachovnice[5][0] = 0;
sachovnice[5][1] = 0;
sachovnice[5][2] = 0;
sachovnice[5][3] = 0;
sachovnice[5][4] = 0;
sachovnice[5][5] = 0;
sachovnice[5][6] = 0;
sachovnice[5][7] = 0;
sachovnice[6] = new Array(8);
sachovnice[6][0] = 0;
sachovnice[6][1] = 0;
sachovnice[6][2] = 0;
sachovnice[6][3] = 0;
sachovnice[6][4] = 0;
sachovnice[6][5] = 0;
sachovnice[6][6] = 0;
sachovnice[6][7] = 0;
sachovnice[7] = new Array(8);
sachovnice[7][0] = 0;
sachovnice[7][1] = 0;
sachovnice[7][2] = 0;
sachovnice[7][3] = 0;
sachovnice[7][4] = 0;
sachovnice[7][5] = 0;
sachovnice[7][6] = 0;
sachovnice[7][7] = 0;
tahyj = new Array(8);
tahyj[0] = -2;
tahyj[1] = -2;
tahyj[2] = -1;
tahyj[3] = 1;
tahyj[4] = 2;
tahyj[5] = 2;
tahyj[6] = -1;
tahyj[7] = 1;
tahyi = new Array(8);
tahyi[0] = -1;
tahyi[1] = 1;
tahyi[2] = 2;
tahyi[3] = 2;
tahyi[4] = -1;
tahyi[5] = 1;
tahyi[6] = -2;
tahyi[7] = -2;
var j = document.getElementById('polohaj').value;
var i = document.getElementById('polohai').value;
sachovnice['+j+']['+i+'] = 1;
for(i=1; i<=7; i++){
pomj = j + tahyj[i];
pomi = i + tahyi[i];
if(pomj >= 0 && pomj <= 7 && pomi >= 0 && pomi <= 7) {
if(pomj % 2 === 0 && pomi % 2 === 0) {
sudepolicko = 1;
sachovnice['+pomj+']['+pomi+'] = 2;
}
else {
sudepolicko = 0;
sachovnice['+pomj+']['+pomi+'] = 2;
}
}
}
// get the reference for the body
var body = document.getElementsByTagName("body")[0];
var black = 1;
// creates a <table> element and a <tbody> element
var tbl = document.createElement("table");
var tblBody = document.createElement("tbody");
var div = document.createElement("div");
// creating all cells
for (var y = 0; y <8; y++) {
// creates a table row
var row = document.createElement("tr");
for (var z = 0; z <8; z++) {
// Create a <td> element and a text node, make the text
// node the contents of the <td>, and put the <td> at
// the end of the table row
var cell = document.createElement("td");
// width and height
cell.style.width = cell.style.height = '44px';
if(sachovnice['y']['z'] == 2) {
cell.style.backgroundColor = "yellow";
}
else if(sachovnice[y][z] == 1 && sudepolicko == 1) {
cell.style.background = "url(figurky/tmave/kun.png)";
}
else if(sachovnice['y']['z'] == 1 && sudepolicko === 0) {
cell.style.background = "url(figurky/svetle/kun.png)";
}
else if(sachovnice[y][z] === 0 && black == 1) {
cell.style.background = "url(figurky/b.png)";
}
else {
cell.style.background = "url(figurky/w.png)";
}
// invert color, not at the end
if(i != 7) {
black = !black; }
//cell.appendChild(cellText);
row.appendChild(cell);
id = j.toString(10)+i.toString(10);
cell.setAttribute("id"," "+id+"");
}
// add the row to the end of the table body
tbl.appendChild(row);
// appends <table> into <body>
body.appendChild(tbl);
body.appendChild(div);
// sets the border attribute of tbl to 2;
tbl.setAttribute("border", "2");
div.setAttribute("id","levy");
}
}
</script>Kód: Vybrat vše
<script type="text/javascript">
function sachovnice() {
// get the reference for the body
var body = document.getElementsByTagName("body")[0];
var black = 1;
// creates a <table> element and a <tbody> element
var tbl = document.createElement("table");
var tblBody = document.createElement("tbody");
// creating all cells
for (var j = 0; j <7; j++) {
// creates a table row
var row = document.createElement("tr");
for (var i = 0; i <7; i++) {
// Create a <td> element and a text node, make the text
// node the contents of the <td>, and put the <td> at
// the end of the table row
var cell = document.createElement("td");
// width and height
cell.style.width = cell.style.height = '44px';
if(black) cell.style.background = "url(figurky/b.png)";
else cell.style.background = "url(figurky/w.png)";
// invert color, not at the end
if(i != 7) black = !black;
//cell.appendChild(cellText);
row.appendChild(cell);
indentifikator = j.toString(10) + i.toString(10);
cell.setAttribute("id", "+identifikator+")
}
// add the row to the end of the table body
tblBody.appendChild(row);
}
// put the <tbody> in the <table>
tbl.appendChild(tblBody);
// appends <table> into <body>
body.appendChild(tbl);
// sets the border attribute of tbl to 2;
tbl.setAttribute("border", "2");
tbl.setAttribute("id", "sachovnice");
//document.getElementById("sachovnice").rows[0].cells[0].id;
//cell.setAttribute("alt", "sachovnice")
}
</script>Děkuji za odpověď

