我正在使用这个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';
}
}
}
错误是:
idx<len;
处的分号是出错的地方。
有人可以通过上面的代码片段解释我的错误吗?
非常感谢。
答案 0 :(得分:1)
将其更改为:
// 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';
}
}
}
答案 1 :(得分:1)
**// 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';
}
}
}**