首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jquery会话和表过滤

Jquery会话和表过滤
EN

Stack Overflow用户
提问于 2010-05-03 23:22:32
回答 1查看 455关注 0票数 0

这是我的Jquery

代码语言:javascript
复制
     <script type="text/javascript">  
 $(function() {
 var from = $.session("from");
var to = $.session("to");

var $th = $('#theTable').find('th');
// had to add the classes here to not grab the "td" inside those tables
var $td = $('#theTable').find('td.bluedata,td.yellowdata');

 $th.hide();
 $td.hide();

if (to == "Select" || from == "Select") {
  // shortcut - nothing set, show everything
  $th.add($td).show();
  return;
}

 var filterArray = new Array();
filterArray[0] = to;
 filterArray[1] = from;

  $.each(filterArray, function(i){
    if (filterArray[i].toString() == "Select")
    {
        filterArray[i] = "";
    }
});   
$($th).each(function(){
    if ($( this,":eq(0):contains('" + filterArray[0].toString() + "')") != null
        && $(this,":eq(1):contains('" + filterArray[1].toString() + "')") != null)
    {
        $(this).show();
    }
});
 $($td).each(function(){
    if ($( this,":eq(0):contains('" + filterArray[0].toString() + "')") != null
        && $(this,":eq(1):contains('" + filterArray[1].toString() + "')") != null)
    {
        $(this).show();
    }
}); 
  });
  </script>

这是我的桌子

代码语言:javascript
复制
 <table border="1" id="theTable">
    <tr class="headers">
        <th class="bluedata"height="20px" valign="top">63rd St. &amp; Malvern Av. Loop<BR/></th>
        <th class="yellowdata"height="20px" valign="top">52nd St. &amp; Lansdowne Av.<BR/></th>
        <th class="bluedata"height="20px" valign="top">Lancaster &amp; Girard Avs<BR/></th>
        <th class="yellowdata"height="20px" valign="top">40th St. &amp; Lancaster Av.<BR/></th>
        <th class="bluedata"height="20px" valign="top">36th &amp; Market Sts<BR/></th>
            <th class="bluedata"height="20px" valign="top">6th &amp; Market Sts<BR/></th>
        <th class="yellowdata"height="20px" valign="top">Juniper Station<BR/></th>
    </tr>
    <tr>
        <td class="bluedata"height="20px" title="63rd St. &amp; Malvern Av. Loop">
        <table width="100%"><tr><td>12:17am</td></tr><tr><td>12:17am</td></tr><tr><td>12:47am</td></tr></table>
        </td>
        <td class="yellowdata"height="20px" title="52nd St. &amp; Lansdowne Av.">
        <table width="100%"><tr><td>12:17am</td></tr><tr><td>12:17am</td></tr><tr><td>12:47am</td></tr></table>
        </td>
         <td class="bluedata"height="20px" title="Lancaster &amp; Girard Avs">
        <table width="100%"><tr><td>12:17am</td></tr><tr><td>12:17am</td></tr><tr><td>12:47am</td></tr></table>
         </td>
        <td class="yellowdata"height="20px" title="40th St. &amp; Lancaster Av.">
        <table width="100%"><tr><td>12:17am</td></tr><tr><td>12:17am</td></tr><tr><td>12:47am</td></tr></table>
        </td>
        <td class="bluedata"height="20px" title="36th &amp; Market Sts">
        <table width="100%"><tr><td>12:17am</td></tr><tr><td>12:17am</td></tr><tr><td>12:47am</td></tr></table>
        </td>
            <td class="bluedata"height="20px" title="6th &amp; Market Sts">
        <table width="100%"><tr><td>12:17am</td></tr><tr><td>12:17am</td></tr><tr><td>12:47am</td></tr></table>
        </td>
        <td class="bluedata"height="20px" title="Juniper Station">
        <table width="100%"><tr><td>12:17am</td></tr><tr><td>12:17am</td></tr><tr><td>12:47am</td></tr></table>
        </td>
    </tr>
</table>

我以前在这里问过问题,我已经成功地将textbox值转换为下拉更改。然而,这有一点不同。我正在使用会话插件(它工作得很好)。在一个页面上,我有一组普通的下拉列表,在提交时,你会被带到一个单独的页面,该页面运行上面的函数,但是所有的行/列都会显示,它们似乎根本没有过滤。

编辑:看过代码后,我认为这是因为如果项目存在(!= null),它只显示所有的TH或TR,而不是所选的一个。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-05-04 00:05:40

对于那些感兴趣的人,我已经弄明白了。

代码语言:javascript
复制
     <script type="text/javascript">  
 $(function() {
 var from = $.session("from");
var to = $.session("to");
var $th = $('#theTable').find('th');
var $td = $('#theTable').find('td.bluedata,td.yellowdata');

if (to == "Select" || from == "Select") {
  // shortcut - nothing set, show everything
  $th.add($td).show();
  return;
}

 $th.add($td).hide();
$th.each(function(idx) {
      var notSelected = $(this).text();
      if ((notSelected.indexOf(to) != -1) || (notSelected.indexOf(from) != -1)) {
         // the text had the to or the from in it - so show this tr
         $(this).show();
         // and show its corresponding td
         $td.eq(idx).show();
      }
    });                      
 });
</script>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2759099

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档