contenteditable属性和user-modifycss规则之间的主要区别是什么?
到目前为止,我发现了两个:
user-modify: read-write-plaintext-only我们可以禁用粘贴富文本.user-modify仅在IE10 + contenteditable中受支持,而自5.5版以来在IE中受支持谢谢!
我正在尝试创建一个HTML5 contenteditable div,它只接受纯文本.我在下面使用html和jQuery:
HTML
<div contenteditable="true"></div>
Run Code Online (Sandbox Code Playgroud)
jQuery的
(function () {
$('[contenteditable]').on('paste', function (e) {
e.preventDefault();
var text = null;
text = (e.originalEvent || e).clipboardData.getData('text/plain') || prompt('Paste Your Text Here');
document.execCommand("insertText", false, text);
});
});
Run Code Online (Sandbox Code Playgroud)
但它并不适用于所有浏览器.getData在Internet Explorer浏览器中不支持.我尝试了很多关于stackoverflow的解决方案,但没有一个对我有用.
我也试过了
(function () {
$('[contenteditable]').on('paste', function (e) {
e.preventDefault();
var text = null;
if (window.clipboardData && clipboardData.setData) {
text = window.clipboardData.getData('text');
} else {
text = (e.originalEvent || e).clipboardData.getData('text/plain') || prompt('Paste Your Text Here');
}
document.execCommand("insertText", false, text);
});
});
Run Code Online (Sandbox Code Playgroud)
但在那种情况下 …