xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

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 发布文章使用:只允许注册用户才可以访问!


posted @ 2019-01-23 13:20  xgqfrms  阅读(273)  评论(9编辑  收藏  举报