未捕获的TypeError:无法调用方法' removeClass'未定义,kendo小部件无法正常工作

时间:2013-04-07 11:10:42

标签: javascript jquery kendo-ui

我正在尝试在我的页面上实现少量KendoUI Web小部件,但小部件无法正常工作并出现以下问题:

  1. Editor初始化确定,但很少有问题,例如您何时悬停 它突出显示的选项,但当你离开它应该得到 恢复正常但不
  2. 如果我刷新页面几次 比起一段时间Editor初始化很好但有些时候它没有
  3. 其他小部件kendoDatePicker();kendoDropDownList();是 甚至没有初始化
  4. 我的JQ表单验证也无法在此页面上运行
  5. 此外,在Chrome控制台中,我有以下错误 在Uncaught TypeError: Cannot call method 'removeClass' of undefined的第23679行上kendo.web.js说明了这一点:

    if (value !== DropDownList.fn.value.call(that)) {
                that.text(that.options.title);
                that._current.removeClass("k-state-selected");//This is line # 23679
                that.current(null);
                that._oldIndex = that.selectedIndex = -1;
            }
    

    我在页面上包含以下脚本:

    <script src="/Scripts/jquery-1.7.1.js"></script>
    <script src="/Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script src="/Scripts/jquery.validate.min.js"></script>
    <script src="/Scripts/modernizr-2.5.3.js"></script>
    <script src="/Scripts/kndu/kendo.web.js"></script>
    …
    ….
    
    <script>
        $(document).ready(function () {
            $("#editor").kendoEditor({
                tools: [
                    "bold",
                    "italic",
                    "underline",
                    "strikethrough",
                    "justifyLeft",
                    "justifyCenter",
                    "justifyRight",
                    "justifyFull", "insertUnorderedList",
                    "insertOrderedList",
                    "formatBlock",
                    "createLink",
                    "unlink",
                    "insertImage",
                    "insertHtml",
                    "viewHtml",
                    {
                        name: "customTool",
                        tooltip: "Format as Code",
                        exec: function (e) {
                            var editor = $(this).data("kendoEditor");
                            editor.exec("inserthtml", { value: "<pre>" });
                        }
                    }],
    
            });
            $("#date").kendoDatePicker();
            $("#categry").kendoDropDownList();
    
    
            $("#newpost").validate({
                rules: {
                    ttle: {
                        maxlength: 150,
                        required: true,
                        onlyChars: true
                    },
                    smmry: {
                        maxlength: 250,
                        required: true
                    },
                    editor: {
                        maxlength: 35,
                        required: true
                    },
                    categry: {
                        required: true
                    }
                }
            });
        });
        $.validator.addMethod('onlyChars', function (value) {
            return /^[a-zA-Z ]+$/.test(value);
        }, 'Please enter a valid name with only alphabets');
    </script>
    

1 个答案:

答案 0 :(得分:3)

here中的insertHTML文档说明:

  

insertHtml工具需要一组文本 - 值对。一个   分隔符可以多次包含。

所以你应该有类似的东西:

$("#editor").kendoEditor({
    tools: [
        ...
        "insertHtml",
        ...
    ],
    insertHtml: [
        { text: "label 1", value: "<p>snippet 1</p>" },
        { text: "label 2", value: "<p>snippet 2</p>" }
    ]
});