快速的问题.
我有一个包含3个函数的数组.当我调用我想要执行的特定函数时,它不响应数组中的特定索引.它只执行所有功能,直到它到达最后一个功能.
这是代码:
<p id="sometext">Change Color</p>
<script>
function paintRed() {
var text = document.getElementById('sometext');
text.style.color = "red";
}
function paintBlue() {
var text = document.getElementById('sometext');
text.style.color = "blue";
}
function paintYellow() {
var text = document.getElementById('sometext');
text.style.color = "yellow";
}
var arrcolor = [ paintRed(), paintBlue(), paintYellow()];
arrcolor[0]; //This returns the yellow color and not red//
</script>
Run Code Online (Sandbox Code Playgroud)
所以我的
换颜色
总是返回黄色(数组中的最后一个函数),无论我调用哪个索引,即(arrcolor [0],arrcolor [1]).希望它有意义.谢谢.
我有一个对象
me = {
name: "Mo",
age: 28,
}
我想看看这个对象是否具有属性"高度",例如.(它没有)我怎么能这样做?因此,例如,如果它具有属性"height",我可以给它一个值"5,7".
请注意:我不想检查属性VALUE(me.name),而是检查属性NAME.
谢谢.