使用jquery

时间:2015-07-26 19:36:24

标签: jquery filter html-table

我已经有了这个嵌套表,我试图编写一个只显示我想要显示的信息的JavaScript。

这是一个例子(尽管很难看):

enter image description here

这是表格标记:

<table>
    <tr>
        <td>R1C1</td>
        <td>R1C2</td>
        <td>
            <table class="subtable">
                <tr>
                    <td rowspan=3 class="Category">
                        Fruits
                    </td>
                    <td class="SubItem">
                        Apple
                    </td>
                </tr>
                <tr>
                    <td class="SubItem">
                        Banana
                    </td>
                </tr>
                <tr>
                    <td class="SubItem">
                        Pear
                    </td>
                </tr>
                <tr>
                    <td rowspan=3 class="Category">
                        Countries
                    </td>
                    <td class="SubItem">
                        Norway
                    </td>
                </tr>
                <tr>
                    <td class="SubItem">
                        Finland
                    </td>
                </tr>
                <tr>
                    <td class="SubItem">
                        Sweden
                    </td>
                </tr>
            </table>
        </td>
    </tr>
        <tr>
        <td>R2C1</td>
        <td>R2C2</td>
        <td>
            <table class="subtable">
                <tr>
                    <td rowspan=3 class="Category">
                        Cars
                    </td>
                    <td class="SubItem">
                        Volvo
                    </td>
                </tr>
                <tr>
                    <td class="SubItem">
                        Ford
                    </td>
                </tr>
                <tr>
                    <td class="SubItem">
                        BMW
                    </td>
                </tr>
                <tr>
                    <td rowspan=3 class="Category">
                        Cities
                    </td>
                    <td class="SubItem">
                        Stockholm
                    </td>
                </tr>
                <tr>
                    <td class="SubItem">
                        Helsinki
                    </td>
                </tr>
                <tr>
                    <td class="SubItem">
                        Ulan batur
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>

所以我想要的是以下内容:

如果我搜索宝马,我想展示&#34; R2C1&#34;,&#34; R2C2&#34;,&#34;汽车&#34;,沃尔沃,福特和宝马&#34;。 如果我搜索汽车,我想展示&#34; R2C1&#34;,&#34; R2C2&#34;,&#34;汽车&#34;,沃尔沃,福特和宝马&#34;。

简单地说,我想显示第1,2列,并省略第3栏中的所有内容,但相关信息除外。

现在我希望我可以说我已经开始写这篇文章,但坦率地说,我甚至不知道从哪里开始。我会谷歌,但因为这是其中之一&#34;我 - 甚至不知道什么是搜索&#34;我把它放在这里。

没有必要提供任何完整的解决方案,只需要朝着正确的方向努力。

http://jsfiddle.net/ku1cnthh/1/

感谢您的帮助,如果找不到某些信息,请告诉我。

/帕特里克

1 个答案:

答案 0 :(得分:2)

检查你的小提琴,也许它会给你一些方向:

  1. table doen't change its size but has empty cells $('.subtable').css('visibility', 'hidden')
  2. table doen't change its size $('.subtable').css('visibility', 'hidden') +将班级移至家长
  3. table changes its size but has no empty cells $('.subtable').hide() +将班级移至家长
相关问题