javascript - 使用串联和数组值的点表示法函数
<script src="modernizr-1.7.min.js"></script>
var modernizr_fields = new Array("canvas","video","webgl");
for (i=0; i < modernizr_fields.length; i++) {
document.writeln(modernizr_fields[i] + " ");
if (Modernizr + "." + modernizr_fields[i])
document.writeln("true");
else
document.writeln("false");
document.writeln("<br>");
}
我知道问题出在这一行:“if (Modernizr + “.”+ Modernizr_fields[i])”,因为它总是评估为“true”
请帮助我的语法。
<script src="modernizr-1.7.min.js"></script>
var modernizr_fields = new Array("canvas","video","webgl");
for (i=0; i < modernizr_fields.length; i++) {
document.writeln(modernizr_fields[i] + " ");
if (Modernizr + "." + modernizr_fields[i])
document.writeln("true");
else
document.writeln("false");
document.writeln("<br>");
}
I know the problem is with this line: "if (Modernizr + "." + modernizr_fields[i])" as it is always evaluating to "true"
Please help with my syntax.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要:
格式
obj.field
仅适用于文字字段名称,如果field
是您使用obj[field]
的变量You need:
The format
obj.field
only works with literal field names, iffield
is instead a variable you have you useobj[field]