国产探花免费观看_亚洲丰满少妇自慰呻吟_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()));
        }
    });
});
 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 巨野县| 黄山市| 郴州市| 江门市| 车致| 惠来县| 南郑县| 岳阳市| 荆州市| 济源市| 县级市| 如皋市| 当雄县| 泗水县| 任丘市| 孝感市| 化德县| 如皋市| 南木林县| 化州市| 商洛市| 湖北省| 连平县| 东方市| 略阳县| 马关县| 南投市| 梓潼县| 桐庐县| 湖州市| 左云县| 都昌县| 景洪市| 清镇市| 巴彦淖尔市| 东乌珠穆沁旗| 富宁县| 平凉市| 晴隆县| 资源县| 吉安市|