国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jquery通過select列表選擇框對表格數據進行過濾示例

2019-11-20 20:43:28
字體:
來源:轉載
供稿:網友

jquery通過select列表選擇框對表格數據進行過濾

表格數據

復制代碼 代碼如下:

<table id="example">
    <thead>
        <tr>
            <th>Name</th>
            <th>Surname</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Michael</td>
            <td>Jordan</td>
        </tr>
        <tr>
            <td>Michael</td>
            <td>Jackson</td>
        </tr>
        <tr>
            <td>Bruno</td>
            <td>Mars</td>
        </tr>
    </tbody>
</table>

 JS過濾代碼,其中select是動態生成的
 

復制代碼 代碼如下:

 $("#example > thead th").each(function(i) {
    $("<select />").attr("data-index", i).html($("<option />")).change(function() {
        $("#example > tbody > tr").show().filter(function() {
            var comb = [], children = $(this).children();
            children.each(function(i) {
                var value = $("select[data-index='" + i + "']").val();
                if (value == $(this).text() || value == "") comb.push(1);
            });
            return comb.length != children.length;
        }).hide();
    }).appendTo("body");
});
$("#example > tbody tr").each(function() {
    $(this).children().each(function(i) {
        var that = $(this);
        var select = $("select[data-index='" + i + "']");
        if (!select.children().filter(function() {
            return $(this).text() == that.text();
        }).length) {
            select.append($("<option />").text($(this).text()));
        }
    });
});
 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 福清市| 广河县| 天峨县| 景洪市| 弥勒县| 常州市| 米林县| 资中县| 江津市| 榆中县| 潼关县| 广丰县| 杭锦旗| 太保市| 大渡口区| 正阳县| 青州市| 西吉县| 青河县| 桂东县| 石泉县| 桦甸市| 禄丰县| 子长县| 永宁县| 临江市| 合川市| 湛江市| 铅山县| 扎兰屯市| 肥西县| 富阳市| 克山县| 霍城县| 罗山县| 重庆市| 陕西省| 沙田区| 攀枝花市| 牟定县| 涡阳县|