我有一个应用程序,其中包含以声明方式创建的大量数字/编辑器。我需要向这些编辑器添加一个onpaste事件,以便在粘贴之前将粘贴的内容转换为纯文本。我在触发事件时遇到问题。我已经尝试将事件附加为data-dojo-props中的组件和单独的data-dojo-attach-event属性。两种方法似乎都不管用。
以下是其中一个字段的示例:
<div data-dojo-type="dijit/Editor" id="Editor1" name="Editor1Content"
data-dojo-props="extraPlugins:
['createLink','unlink','fontSize','foreColor','hiliteColor'],
onChange:function(){MarkDocAsChanged();}" data-dojo-attach-
event="onPaste:function(){pasteAsPlainText(event);}" >This is the current
field content</div>有谁能给我指个方向吗?
发布于 2018-06-05 13:59:51
查看dijit/Editor文档,它似乎不支持onPaste事件。您可以尝试将onpaste侦听器附加到widget.domNode,截获该事件,并在那里转换值,然后将其设置为widget.value。
发布于 2018-06-10 15:11:38
// try to registe the paste event with "dojo/on" on the domNode
on(target, "paste", function(event){
var textClipboard = "";
if (typeof event.clipboardData !== "undefined") {// on Chrome & FF
textClipboard = event.clipboardData.getData("text/plain");
} else if (typeof clipboardData !== "undefined") { // IE
textClipboard = clipboardData.getData("text");
}
// use document.execCommand("insertText", false, text) or
// document.execCommand("paste", false, text) in IE to paste content
});https://stackoverflow.com/questions/50578061
复制相似问题