【问题标题】:Hide second row of table jQuery隐藏表格jQuery的第二行
【发布时间】:2012-04-18 10:25:23
【问题描述】:

第一行是用户输入关键字并点击搜索后显示的搜索结果的容器。第二行在网站第一次加载时自动显示 5 个随机新闻结果,而没有用户查询。网站加载后,用户输入一些关键字并点击搜索。现在,根据用户关键字返回的结果和 5 条新闻都将在那里。根据 url 是否附加了任何查询字符串,如果是,我需要隐藏第二行。如何选择第二行?

假设 url 只是:http://mysite/news/pages/default.aspx 然后什么也不做 如果 url 像 http://mysite/news/Pages/default.aspx?k=city,那么隐藏第二行...

 <div class="NewsResultsList">   
        <table border="1" id="table">
            <tr><td>News Results based on user queries</td></tr>
            <tr><td>Random news results</td></tr>
         </table>
    </div>

【问题讨论】:

  • 不确定您是否建议脚本应该嗅探 URL。不要那样做。相反,请在回调的 success 函数中处理表的清空,或者在呈现内容的情况下在服务器端处理。

标签: javascript jquery html-table row hide


【解决方案1】:
//This will hide the second row of the table.
$(".NewsResultsList table tr").eq(1).hide();

供参考:http://api.jquery.com/eq/

【讨论】:

    【解决方案2】:

    许多解决方案。这是我能想到的:

    $("#table").first().next().hide();
    

    【讨论】:

      【解决方案3】:

      看看这个选择器

      $(document).ready(function (){
          $('div.NewsResultsList table tr:eq(1)').remove()
      })​
      

      here's the live example

      注意:您应该将行的 id 更改为其他名称,因为使用该 id 可能会在代码中造成混淆

      【讨论】:

        【解决方案4】:

        另一个选项是$(".NewsResultsList table tr :nth-child(2)").hide();。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2012-08-01
          • 2011-07-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多