我正在尝试从Kendo编辑器中截取文本,如下所示。
var html = " T "; // This sample text I get from Kendo editor
console.log("Actual :" + html + ":");
var text = "";
try {
// html decode
var editorData = $('<div/>').html(html).text();
text = editorData.trim();
console.log("After trim :" + text + ":");
}
catch (e) {
console.log("exception");
text = html;
}
这段代码在一个独立的js文件中(由typescript生成)。当页面加载时,剪切功能无法正常工作。但是,当我在开发者工具控制台窗口中运行相同的代码时,它可以正常工作。
为什么会出现这种情况?
const html: string = $(selector).data("kendoEditor").value();
console.log("Actual :" + html + ":");
let text: string = "";
try {
// html decode
var editorData = $('<div/>').html(html).text();
text = editorData.trim();
console.log("After trim :" + text + ":");
}
catch (e) {
console.log("exception");
text = html;
}
实际上不是空格。它由浏览器呈现为空格,但就 Javascript 而言,它不是空格,而是一个字符串。 - Liam