JQuery FixedTable - PullRequest
       15

JQuery FixedTable

0 голосов
/ 21 июля 2009

Мы нашли плагин JQuery под названием FixedTable, который используется для добавления полос прокрутки в таблицу HTML, и я скопировал их пример кода (см. Ниже) с их веб-сайта в веб-форму ASP.Net. Каждый раз, когда код выполняется, он взрывается в строке 12, $ (". TableDiv"). Each (function (), говоря, что объект ожидался. Кто-нибудь знает, что не так с этим кодом?

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="fixedtable.aspx.cs"       Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="~/js/jquery-1.3.2-vsdoc2.js"></script>
    <script type="text/javascript" src="~/js/jquery.fixedtable.js"></script>
<script type="text/javascript">
    // this "tableDiv" must be the table's class
    $(".tableDiv").each(function() {
        var Id = $(this).get(0).id;
        var maintbheight = 555;
        var maintbwidth = 911;

        $("#" + Id + " .FixedTables").fixedTable({
            width: maintbwidth,
            height: maintbheight,
            fixedColumns: 1,
            // header style
            classHeader: "fixedHead",
            // footer style        
            classFooter: "fixedFoot",
            // fixed column on the left        
            classColumn: "fixedColumn",
            // the width of fixed column on the left      
            fixedColumnWidth: 150,
            // table's parent div's id           
            outerId: Id,
            // tds' in content area default background color                     
            Contentbackcolor: "#FFFFFF",
            // tds' in content area background color while hover.     
            Contenthovercolor: "#99CCFF",
            // tds' in fixed column default background color   
            fixedColumnbackcolor: "#187BAF",
            // tds' in fixed column background color while hover. 
            fixedColumnhovercolor: "#99CCFF"
        });
    });
</script>
<style type="text/css">
    body
    {
        width: 900px;
    }
    p
    {
        float:left;
        width: 100%;
        margin: 20px 0px;
    }
    .fixedColumn .fixedTable td
    {
        color: #FFFFFF;
        background-color: #187BAF;
        font-size: 12px;
        font-weight: normal;
    }

    .fixedHead td, .fixedFoot td
    {
        color: #FFFFFF;
        background-color: #187BAF;
        font-size: 12px;
        font-weight: normal;
        padding: 5px;
        border: 1px solid #187BAF;
    }
    .fixedTable td
    {
        font-size: 8.5pt;
        background-color: #FFFFFF;
        padding: 5px;
        text-align: left;
        border: 1px solid #CEE7FF;
    }
    .tableDiv 
    {

    }
</style>


</head>
<body>
    <form id="form1" runat="server">
    <div id="tableDiv_Arrays" class="tableDiv">
    <table id="Open_Text_Arrays" class="FixedTables">
        <thead>
            <tr>
                <th>
                    Purpose
                </th>
                <th>
                    C#
                </th>
                <th>
                    Php4
                <th>
                <th>
                    Php5
                </th>
                <th>
                    ActionScript
                </th>
                <th>
                    JavaScript
                </th>
                <th>
                    Ruby
                </th>
            </tr>
        <thead>
        <tbody>
            <tr>
                <th>
                    data1
                </th>
                <th>
                    data2
                </th>
                <th>
                    data3
                <th>
                <th>
                    data4
                </th>
                <th>
                    data5
                </th>
                <th>
                    data6
                </th>
                <th>
                    data7
                </th>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <th>
                    Purpose
                </th>
                <th>
                    C#
                </th>
                <th>
                    Php4
                <th>
                <th>
                    Php5
                </th>
                <th>
                    ActionScript
                </th>
                <th>
                    JavaScript
                </th>
                <th>
                    Ruby
                </th>
            </tr>
        </tfoot>
    </table>
</div>

</form>
</body>
</html>

Ответы [ 3 ]

0 голосов
/ 21 июля 2009

Вы уверены, что jQuery запрашивается правильно? Вы можете проверить это с помощью fiddler2 или firebug в firefox.

Также вам понадобится функция готовности документа. Это гарантирует, что дом готов, прежде чем вы начнете манипулировать им.

$(function(){

   $(".tableDiv").each(function() {
        var Id = $(this).get(0).id;
        var maintbheight = 555;
        var maintbwidth = 911;

        $("#" + Id + " .FixedTables").fixedTable({
            width: maintbwidth,
            height: maintbheight,
            fixedColumns: 1,
            // header style
            classHeader: "fixedHead",
            // footer style        
            classFooter: "fixedFoot",
            // fixed column on the left        
            classColumn: "fixedColumn",
            // the width of fixed column on the left      
            fixedColumnWidth: 150,
            // table's parent div's id           
            outerId: Id,
            // tds' in content area default background color                     
            Contentbackcolor: "#FFFFFF",
            // tds' in content area background color while hover.     
            Contenthovercolor: "#99CCFF",
            // tds' in fixed column default background color   
            fixedColumnbackcolor: "#187BAF",
            // tds' in fixed column background color while hover. 
            fixedColumnhovercolor: "#99CCFF"
        });
    });

};

0 голосов
/ 21 июля 2009

Или поместите блок скрипта между тегами </body> и </html> в конце вашего файла.

0 голосов
/ 21 июля 2009

Чтобы получить ошибку «объект ожидается», jQuery даже не должен загружаться. Что с атрибутами src="~/js/jquery-1.3.2-vsdoc2.js" в тегах сценария, с тильдами? Это то, что ваш веб-сервер будет иметь смысл, или это так же неправильно, как выглядит? Во всяком случае, в некотором стиле ваши теги сценария не ссылаются на ваши исходные файлы jQuery таким образом, чтобы это работало.

Кроме того, когда вы сортируете это, tableDiv не существует, когда выполняется содержимое скрипта. Вам нужно будет поместить скрипт в $(document).ready().

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...