document.execCommand & contenteditable
document.execCommand & contenteditable
https://developer.mozilla.org/zh-CN/docs/Web/API/Document/execCommand
https://developer.mozilla.org/zh-CN/docs/Web/HTML/Global_attributes/contenteditable
demo
click copy
https://codepen.io/webgeeker/pen/XOJaEP
<blockquote contenteditable="true">
<p>Edit this content to add your own quote</p>
</blockquote>
<cite contenteditable="true">-- Write your own name here</cite>
.output {
font: 1rem 'Fira Sans', sans-serif;
}
blockquote {
background: #eee;
border-radius: 5px;
margin: 16px 0;
}
blockquote p {
padding: 15px;
}
cite {
margin: 16px 32px;
}
blockquote p::before {
content: '\201C';
}
blockquote p::after {
content: '\201D';
}
[contenteditable='true'] {
caret-color: red;
}
getSelection & execCommand
window.getSelection().toString()
window.document.execCommand(`copy`);
// true
document.execCommand(`copy`);
// true
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/10308392.html
未经授权禁止转载,违者必究!