此 Javascript 代码段的 W3C 验证错误
W3C Validation Errors with this Javascript snippet
我在这个Javascript代码中遇到了w3c验证错误,想知道一个善良的绅士/女士是否会给我一点时间。
// hide all element nodes within some parent element
function hideAll(parent) {
var children = parent.childNodes, child;
// loop all the parent's children
for (var idx=0, len = children.length; idx<len; ++idx) { /* ERROR HERE */
child = children.item(idx);
// if element node (not comment- or textnode)
if (child.nodeType===1) {
// hide it
child.style.display = 'none';
}
}
}
错误是:
- 元素 "len" 未定义
- 字符 ";" 属性规范列表中不允许
idx<len;
处的分号是出错的地方。
有人可以解释一下上面的代码片段哪里出了问题吗?
非常感谢。
将其更改为:
// hide all element nodes within some parent element
function hideAll(parent) {
var children = parent.childNodes, child;
// loop all the parent's children
var len = children.length;
for (var idx=0; idx<len; ++idx) { /* ERROR HERE */
child = children.item(idx);
// if element node (not comment- or textnode)
if (child.nodeType===1) {
// hide it
child.style.display = 'none';
}
}
}
**// hide all element nodes within some parent element
function hideAll(parent)
{
var children = parent.childNodes, child;
// loop all the parent's children
var len=children.length;
for (var idx=0; idx<len; ++idx)
{ /* ERROR HERE */
child = children.item(idx);
// if element node (not comment- or textnode)
if (child.nodeType===1)
{
// hide it
child.style.display = 'none';
}
}
}**
相关文章:
- 正在验证8个真/假复选框或复选框中的2个
- 借助asp.net验证或java脚本对多个文本进行验证
- 如何使用w3c验证程序API
- w3c验证器检查站点的缓存版本
- 要验证的数据cfasync(W3C)
- JSF 1.2 注入导致 w3c 验证失败的 javaScript
- JavaScript 中 的 W3C 验证
- 如何包含 JavaScript 代码,以便它通过 w3c 验证器
- 错误验证 W3C HTML5 img noscript facebook.com.
- 此 Javascript 代码段的 W3C 验证错误
- W3C没有;t验证谷歌地图api
- 包括javascript文件和w3c验证
- W3c验证器和for (var i=0;i
- XHTML Mobile 1.0 -由于脚本导致W3C验证无效
- 在我的textArea中的W3C Html验证器
- AngularJS应用没有通过官方的W3C HTML5验证
- W3C验证器:元素头缺少子元素标题的必需实例
- W3C验证-脚本标记-Javascript或其他东西
- 来自 W3C 验证程序的错误“元素脚本不得具有属性延迟,除非还指定了属性 src”
- 如何将用户创建的HTML发送到W3C验证器以进行自动检查,而不会出现跨域错误