简体   繁体   English

在javascript中显示/隐藏链接

[英]show/hide link in javascript

I have 4 links which place under seperate <td> , I want to show/hide the td based on a particular selection of parent object 我有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>

here is code: 这是代码:

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

The code works but the <td> is still there it should be removed when I hide it. 该代码有效,但是<td>仍然存在,当我隐藏它时应将其删除。

You have to use the parentNode attribute, which will return the parent element, here the <td> : 您必须使用parentNode属性,该属性将返回父元素,这里是<td>

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

尝试这个:

document.getElementById("first").parentNode.style.display = 'none';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM