无法设置/读取未定义的属性 [英] Cannot set/ read property of undefined
本文介绍了无法设置/读取未定义的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图做一个网站布局类型的东西,你点击一个属性和一个值,面板改变了那个东西。我需要能够有一个接口数组,我可以点击通过。
I'm trying to make an 'site layout' type thing where you click on an attribute and a value and the panel changes to that thing. I need to be able to have an array of interfaces that I can click through.
我收到错误无法设置/读取未定义的属性颜色
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();
}
造成麻烦:
This is the HTML thats causing trouble:
<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>
推荐答案
= new Array()两次。如果你把它,你应该没关系。
You call "var interfaces = new Array()
" twice. If you take that out, you should be okay.
这篇关于无法设置/读取未定义的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文