0

我正在使用kendo editor. 当我想为多行创建项目列表时,遇到问题(见图)

图片 为了解决这个问题,我创建了自定义按钮:

 {
                name: "custom",
                tooltip: "Insert a List",
                exec: function(e) {
                    var editor = $(this).data("kendoEditor");
                    var selectedText = editor.getSelection().toString();
                    if (selectedText.length > 0) {
                        var list = selectedText.split("\n").join("</li><li>");
                        list = "<ul><li>" + list.substring(0, list.length - 5) + "</ul>";
                    }
                    editor.exec("inserthtml", { value: list });
                }
            }

此代码在选择整行文本时工作正常,但当仅选择行的一部分(不是整行只是行的某个字符)时,列出不是从行的起点创建的项目。

4

1 回答 1

0

在执行toString()Selection 对象之前,您需要使用 Selection 和 Range API 以获得完整的文本节点,然后应用拆分。

https://developer.mozilla.org/en-US/docs/Web/API/Selection

https://developer.mozilla.org/en-US/docs/Web/API/Range

于 2017-05-18T20:55:09.877 回答