【问题标题】:Uncaught TypeError: undefined is not a function (anonymous function) php javascriptUncaught TypeError: undefined is not a function (anonymous function) php javascript
【发布时间】:2014-12-15 13:18:22
【问题描述】:

我对 javascript 不是很熟悉,在这里我也很陌生。我在控制台上收到一个错误,显示 Uncaught TypeError: undefined is not a function。

我正在尝试对表格进行排序并在 php 中创建分页。没有致命错误,但它不起作用。我不知道为什么。这是我的代码:

header.php

<!-- Mobile viewport optimisation -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<!-- Add meta data here -->

<link id="bootstrapFlexible" href="styles/flexible-columns.css" rel="stylesheet" type="text/css"/>

<link id="bootstraptheme" rel="stylesheet" type="text/css" href="css/bootstrap.css">



<link rel="stylesheet" type="text/css" href="css/jquery.css" />

<script src="js/jquery-1.9.1.js"></script>
<script src="js/jquery-ui.js"></script>
<script src="js/jquery.tablesorter.js" type="text/javascript"></script> 
<script type="text/javascript"> 
    $(document).ready(function() { 
        $("table").tablesorter({ 
            sortList: [[2,0]],
            // pass the headers argument and assing a object 
            headers: { 
                // assign the secound column (we start counting zero) 
                5: { 
                    // disable it by setting the property sorter to false 
                    sorter: false 
                }           
            } 
        }); 
    });
</script>

<meta charset="utf-8"/>

    <script>
        function settheme() {
            if (localStorage.getItem("settheme") === null) {

            }else{
                var theme = localStorage['settheme'];
                document.getElementById('bootstraptheme').href = theme;
            }
        };
         window.onload = settheme;

    </script>

这是我的桌子:

$query = $dbh -> query("SELECT COUNT(*) FROM reminders r 
        JOIN reminder_type rt 
        ON r.type_of_reminder = rt.reminder_type_id
        JOIN subjects s
        ON r.subject = s.subject_id");

$num_rows=$query->rowCount();
$rows = $query->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT);
$pages = new Paginator;
$pages->items_total = $rows[0];
$pages->mid_range = 5; // Number of pages to display. Must be odd and > 3
$pages->paginate();
echo $pages->display_pages();
echo "<span class=\"\">".$pages->display_jump_menu().$pages->display_items_per_page()."</span>";

echo "<form method='POST'>
    <input type='text' name='search_key'/>
    <input type='submit' name='search_button' value='S E A R C H'/>
    </form>";

echo '<table style="width:100%;margin:auto; text-align: center;" id="bord" class="tablesorter">';
echo '<thead id="table_head">
<tr style="height:50px;font-size:18px;font-weight:bold; background:#00a651; color:#fff;"">';
echo "  <th class='thh'>Name</th>
        <th class='thh'>Subject</th>
        <th class='thh'>Reminder Type</th>
        <th class='thh'>Description</th>
        <th class='thh'>Date of Deadline</th>
        <th class='thh'>Time of Deadline</th>
        <th>Option</th>
        </tr></thead>
        <tbody>";

这是我从网上得到的paginator 类。

感谢您的所有建议。我已经查看了 SO,但似乎找不到解决方案。所以,谢谢你们!

【问题讨论】:

  • 我们没有使用PHP代码,把生成的HTML贴出来让我们看看吧!更好的是 JSfiddle!
  • 这会有帮助吗? @MichaelLumbroso link

标签: javascript php jquery pagination


【解决方案1】:

在你放的脚本部分 };关闭函数 settheme()。

<script>
    function settheme() {
        if (localStorage.getItem("settheme") === null) {

        }else{
            var theme = localStorage['settheme'];
            document.getElementById('bootstraptheme').href = theme;
        }
    };

尽量去掉多余的;

【讨论】:

  • 仍然是同样的错误,这是控制台说有错误的行。 . $("table").tablesorter({
  • 那你有插件包含的问题。检查路径 js/jquery.tablesorter.js 你在这个文件上没有 404 吗?
  • 没有。我也在我开发的网站中使用它,但它工作正常。但是当我在这里实现它时,它不再起作用了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-12-30
  • 2014-08-15
  • 2015-01-14
  • 2014-07-06
  • 2014-09-01
  • 2015-11-04
  • 2013-03-06
相关资源
最近更新 更多