我试图制作一个网站布局'键入一个单击属性和值的东西,面板更改为该东西。我需要能够拥有一系列可以点击的界面。
我收到错误cannot set/read property colors of undefined
var panel = "";
var colorType = "texts";
var interfaces = new Array();
interfaces.push(new Interface());
var colors = 'black'
var idx = 0;
var interfaces = new Array();
function Interface(c)
{
this.colors = c;
}
function changeColor()
{
if(panel != '')
{
if(colorType == 'texts')
{
document.getElementById(panel).style.color = interfaces[idx].colors;
}
if(colorType == 'background')
{
document.getElementById(panel).style.backgroundColor = interfaces[idx].colors;
}
}
}
function changeSize()
{
document.getElementById(panel).style.fontSize = interfaces[idx].getElementById('fsizes').value +'px';
}
function panelClicked()
{
document.getElementById('texts').style.borderStyle = 'solid';
document.getElementById('background').style.borderStyle = 'none';
colors = 'black';
colorType = 'texts';
changeColor();
}
这是造成麻烦的HTML:
<table style = "width:90px;">
<tr>
<td class = 'colors' style = "background-color:red;" onclick = "interfaces[idx].colors = 'red'; changeColor();"></td>
<td class = 'colors' style = "background-color:orange;" onclick = "interfaces[idx].colors = 'orange'; changeColor();"></td>
<td class = 'colors' style = "background-color:yellow;" onclick = "interfaces[idx].colors = 'yellow'; changeColor();"></td>
</tr>
<tr>
<td class = 'colors' style = "background-color:green;" onclick = "interfaces[idx].colors = 'green'; changeColor();"></td>
<td class = 'colors' style = "background-color:blue;" onclick = "interfaces[idx].colors = 'blue'; changeColor();"></td>
<td class = 'colors' style = "background-color:purple;" onclick = "interfaces[idx].colors = 'purple'; changeColor();"></td>
</tr>
<tr>
<td class = 'colors' style = "background-color:lightpink;" onclick = "interfaces[idx].colors = 'lightpink '; changeColor();"></td>
<td class = 'colors' style = "background-color:thistle;" onclick = "interfaces[idx].colors = 'thistle'; changeColor();"></td>
<td class = 'colors' style = "background-color:black;" onclick = "interfaces[idx].colors = 'black'; changeColor();"></td>
</tr>
</table>
答案 0 :(得分:2)
您拨打“var interfaces = new Array()
”两次。如果你把它拿出来,你应该没问题。