1

我有 4 个单独放置的链接<td>,我想根据父对象的特定选择显示/隐藏 td

<td nowrap align=right id="dis_mirr" style="visiblility: visible;">
    <a id="first" style=font-weight:normal href=javascript:createwin();>
        &nbsp;Mirror&nbsp;
    </a>
</td>
<td nowrap align=right>
    <a id="second" style=font-weight:normal href=javascript:breakwin();>
        &nbsp;Break Mirror
    </a>
</td>

这是代码:

if(record.get('model') == 'top'){
    document.getElementById('first').visibility = "hidden";
}else{
    document.getElementById('first').visibility = "visible";
}

该代码有效,但<td>仍然存在,当我隐藏它时应该将其删除。

4

2 回答 2

4

您必须使用 parentNode 属性,该属性将返回父元素,这里是<td>

if(record.get('model') == 'top'){
    document.getElementById('first').parentNode.visibility = "hidden";
} else {
    document.getElementById('first').parentNode.visibility = "visible";
}
于 2012-08-22T08:49:45.217 回答
1

尝试这个:

document.getElementById("first").parentNode.style.display = 'none';
于 2012-08-22T08:46:12.440 回答