无法设置/读取未定义的属性
Cannot set/ read property of undefined
我正在尝试制作一个"site layout"类型的东西,点击一个属性和一个值,面板就会更改为那个东西。我需要能够拥有一系列可以点击的界面。
我收到错误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>
您调用"var interfaces = new Array()
"两次。如果你把它拿出来,你应该没事的。
相关文章:
- 将对象作为参数传递后的未定义属性
- 检查链接对象形式中未定义属性的最佳实践是什么
- PhantomJS中的evalute内部未定义属性
- 访问数字类型的未定义属性
- 如何处理未定义属性的未定义属性 javascript 类型错误
- 返回未定义属性的脚本
- 类型错误:无法读取 ng-repeat 的未定义属性
- JavaScript-Disqus如何处理其“;disqus_config”;包含未定义属性的函数
- 是对HTMLElement#样式的未定义属性的赋值的返回值,保证与赋值相同
- 最好检查未定义属性或设置为空
- 如何解决这个未定义属性的node.js错误?
- 如何在JavaScript中挽救对象的未定义属性?
- AngularJS和PHP -注意:未定义属性:stdClass
- 主干模型删除未定义属性
- if else子句中未定义对象的未定义属性
- Javascript数组问题:无法读取未定义属性
- 当尝试使用未定义属性进行筛选时,Lodash将排除项
- 在Javascript数组的中途未定义属性
- Knockout arrayForEach未定义属性
- javascript中未定义属性的简写,初始化和赋值属性