0

I am learning code, but have been tasked with creating a table, and when the user selects from multiple drop-down lists, whatever the user selected, is displayed in the table. (non-selected rows get hidden)

I want to place the code into a new html file and have it run. (my test is to cut and paste it into a txt doc, then change the name to html for testing) I can do this for other types of scripts, but for some reason, I cannot seem to get this one to run.

<script language="javascript"> 
 $(document).ready(function () {
        $('select.ddlFilterTableRow').bind('change', function () {
            $('select.ddlFilterTableRow').attr('disabled', 'disabled');
           $('#tableRegisterKids').find('.Row').hide();
            var critriaAttribute = '';

            $('select.ddlFilterTableRow').each(function () {
                if ($(this).val() != '0') {
                    critriaAttribute += '[data-' + $(this).data('attribute') + '="' + $(this).val() + '"]';
                }
            });

            $('#tableRegisterKids').find('.Row' + critriaAttribute).show();
            $('#headerCount').html($('table#tableRegisterKids tr.Row:visible').length + ' Registered Kids');
            $('select.ddlFilterTableRow').removeAttr('disabled');
        });
    });</script>



<select id="ddlAge" class="ddlFilterTableRow" data-attribute="age">
    <option value="0">Select All</option>
    <option value="10">10</option>
    <option value="8">8</option>
    <option value="6">6</option>
</select>
<select id="ddlSport" class="ddlFilterTableRow" data-attribute="sports">
    <option value="0">Select All</option>
    <option value="Foot Ball">Foot Ball</option>
    <option value="Chess">Chess</option>
    <option value="Cricket">Cricket</option>
    <option value="Bowling">Bowling</option>
</select>
<h1 id="headerCount"></h1>
<table id="tableRegisterKids">
    <tr>
        <th>Fullname</th>
        <th>Age</th>
        <th>Sport</th>
    </tr>
    <tr class="Row" data-age="10" data-sports="Foot Ball">
        <td>Thulasi Ram.S</td>
        <td>10</td>
        <td>Foot Ball</td>
    </tr>
    <tr class="Row" data-age="8" data-sports="Cricket">
        <td>Ram</td>
        <td>8</td>
        <td>Cricket</td>
    </tr>
    <tr class="Row" data-age="6" data-sports="Chess">
        <td>Ram Kumar.S</td>
        <td>6</td>
        <td>Chess</td>
    </tr>
    <tr class="Row" data-age="8" data-sports="Bowling">
        <td>Dinesh Kumar.S</td>
        <td>8</td>
        <td>Bowling</td>
    </tr>
    <tr class="Row" data-age="6" data-sports="Bowling">
        <td>Raja Ram.S</td>
        <td>6</td>
        <td>Bowling</td>
    </tr>
    <tr class="Row" data-age="10" data-sports="Chess">
4

1 回答 1

0

将代码复制并粘贴到文本文件中时是否包含 jQuery?代码在这里运行良好。http://jsfiddle.net/zLPMV/

您需要确保将 jQuery 包含到您的页面中,一个简单的测试是从谷歌资源中获取它。将此行代码添加到脚本标记上方的文本文件中。

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

PS您是自己编写此代码还是只是将其用作资源并试图使其运行?

于 2013-11-07T18:44:09.100 回答