【问题标题】:jquery plugin not working - TypeError 'Undefined is not a function' in safarijquery 插件不起作用 - Safari 中的 TypeError 'Undefined is not a function'
【发布时间】:2011-09-29 17:36:35
【问题描述】:

我正在使用 jquery treeview 插件在层次结构视图中创建一个列表。这在 Firefox 中运行良好,但在 safari 和 'Uncaught TypeEror : Object [object object] has no method 'treeview' in chrome 错误控制台中会导致类似“TypeError: undefined is not a function”的错误。

这里是代码sn-p

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link type="text/css" href="./methodeditor4.css" rel="stylesheet" />
<link type="text/css" href="../../css/cupertino/jquery-ui-1.8.16.custom.css" rel="Stylesheet" />
<script type="text/javascript" src="../../js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="../../js/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="./treeview/jquery.treeview.js"></script>    

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







<title>Method editor</title>
<script>


$(function() {

        getmethodgroups();

});



function getmethodgroups(){

    $.ajax({
        url: "listmethods.php",
        cache:false,
        success: function(data){
        var methgroups = JSON.parse(data);
        for ( var i=0; i < methgroups.length; i++ ) {
            $(".list").append("<li  class=\"mgclick filetree\" id=" + methgroups[i] + "><span class=folder>" + methgroups[i] + "</span><ul></ul>" );
            $(".list").append("</li>");
            };
        $("#list").treeview({
           collapsed: true
        });
        }
    });




}
</script>
</head>

<body > 

( has all the elements )
</body>
</html>

页面中加载了treeview插件的脚本,路径正确。其他一些插件(如选项卡)也会发生同样的情况。 Firefox 运行良好,问题出在 safari 和 chrome 上。有什么线索吗?

谢谢, 斯里尼。

【问题讨论】:

  • 我看到 #list 并且您正在附加到 .list - 我没有看到完整的代码。您能否将代码托管在某个 url 中以进行测试并为您提供解决方案。
  • 嗨,很抱歉让您感到困惑。该元素具有相同的类和 id 名称。
  • 您不应该单独附加结束&lt;/li&gt;。只需一个 append 电话即可完成所有操作。

标签: jquery jquery-ui jquery-plugins


【解决方案1】:

onReady 更改

$(function() {
//add this
 $("#list").treeview();
        getmethodgroups();
});

脚本更改#

 var branches = "";
for ( var i=0; i < methgroups.length; i++ ) {
   branches = branches + "<li  class=\"mgclick filetree\" id=" + methgroups[i] + "><span class=folder>" + methgroups[i] + "</span><ul></ul></li>"
                };
        $(branches).appendTo("#list");
            $("#list").treeview({
               add: branches
            });

html

<body>
  <ul id="#list" class="filetree">
  </ul>
</body>

【讨论】:

  • 我想我找到了你的树视图版本,修改了我的代码以匹配那个实现。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-09
  • 1970-01-01
  • 2015-06-24
  • 2021-06-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多