如果子跨度为空,则隐藏单元格内容 [英] hide cell content if child spans are empty

查看:146
本文介绍了如果子跨度为空,则隐藏单元格内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个表'OfficeInfo',有两行,每行2个单元格。每个单元格都有Office信息,如姓名,地址,电话和方向链接。我需要隐藏方向链接(基于地址值的谷歌地图链接)或隐藏整个单元格,如果其他信息,如名称,地址,电话等是空白的..小时说其他一切都是空的,隐藏'地图和方向'链接以及整个单元格...如何在Jquery中做?

There is a table 'OfficeInfo' with two rows with 2 cell each. Each cell will have Office info like name, address, phone and direction link. I need to hide the direction link (google map link based on the address value) or hide the whole cell if other info like name, addreses, phone etc are blank..lets say everything else is empty, hide the 'map and directions' link as well or the whole cell...How to do in Jquery?

<table class="OfficeInfo" border="0" style="width: 100%" cellspacing="10px" cellpadding="15px">
    <tr>
        <td class="Office1" style="width=40%">  
            <span class="OfficeName">
                Munster Women&#39;s Center<br />
            </span>
            <span class="Address">
                1111 North Ronald Reagan Pkwy,  <br />&#160;Avon,IN 46123      
            </span> 
            <span class="Phone">
                (317) 342-1254</span><br />
            <a class="mapdirectionsLink" href="#">map &#38; directions&#62;</a>
            <br />
            <br />
            <span class="Hours">
                MTW: 9:00 AM- 5:00 PM 
            </span>
        </td>
        <td>
            <span class="OfficeName">  </span>
            <span class="Address"></span>                                     
            <span class="Phone"></span>
            <br />
            <a class="mapdirectionsLink" href="#">map and directions</a>
            <br />
            <br />
            <span class="Hours"></span> 
        </td>
    </tr>
    <tr>
        <td>
            Office3
        </td>
        <td>
            Office4
        </td>   
    </tr>
</table>


推荐答案

因为你没有包含你的最终html它是很难说。总是尝试包括我们将在页面上看到的内容,而不是通用的sharepoint调用。

As you don't include your final html it is tough to say. Always try and include what we will see on the page, not generic sharepoint calls.

http://jsfiddle.net/Ctjcv/7/

在这个例子中,我检查每个单元格是否包含除了地图类。如果没有,那么我们可以安全地隐藏它。您将看到cell1显示链接,因为其他数据存在而单元格2不存在。

In this example I check whether each cell contains any children other than the map class. If not then we can safely hide it. You will see that cell1 shows the link because other data is present while cell 2 does not.

$('.OfficeInfo td').each( function() {
    if ($(this).children(':empty').not('.mapdirectionsLink, br').length > 0) {
        $(this).children('.mapdirectionsLink').hide();   
    }
});

这篇关于如果子跨度为空,则隐藏单元格内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆