iT邦幫忙

1

JQuery 篩選

https://ithelp.ithome.com.tw/upload/images/20180418/20108277RjeNLuCzXi.jpg
安安 各位大大好
我想用一個checkbox來控制
打勾的話顯示全資料
沒打勾的話就把已婚跟男生都顯示

有點不知道要怎麼下

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
froce
iT邦大師 1 級 ‧ 2018-04-18 19:26:44
最佳解答

就對所有的tr做檢查,然後裡面的td去查值,如果是未婚女性,就顯示,其他用hide就行了。

var trs = $('table>tbody>tr')

function filter_for_table(){
    trs.each(function(){
        var checker = true;
        $(this).find('td').each(function(){
            if ($(this).text() == "男" || $(this).text() == "已婚"){
                checker = false;
            }
        });
        if (!checker){
            $(this).hide();
        }
    });
}

function restore(){
    trs.each(function(){
        $(this).show();
    });
}

JS Bin

ccutmis iT邦高手 2 級 ‧ 2018-04-19 08:33:14 檢舉

/images/emoticon/emoticon12.gif

froce iT邦大師 1 級 ‧ 2018-04-19 11:30:34 檢舉

實際上資料量多我會用ajax去重取就是了。XD

我要發表回答

立即登入回答