Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <textarea id="txt">阅文旗下囊括 QQ 阅读、起点中文网、新丽传媒等业界知名品牌,拥有 1450 万部作品储备,940 万名创作者,覆盖 200 多种内容品类,触达数亿用户,已成功输出包括《庆余年》《赘婿》《鬼吹灯》《琅琊榜》《全职高手》在内的动画、影视、游戏等领域的 IP 改编代表作。</textarea>
  <button id="btn">选中“阅文”</buttton>
  <button id="btn1">光标移动到“阅文”后</buttton>
  <button id="btn2">还原选区</buttton>
  <button id="btn3">在选区插入新内容</buttton>
  <button id="btn4">在5-10的地方插入新内容</buttton>
              
            
!

CSS

              
                textarea{
  width: 100%;
  height: 100px;
}
button{
  margin: 3px
}
              
            
!

JS

              
                btn.onclick = () => {
  
	txt.setSelectionRange(0,2)
    txt.focus();
}

btn1.onclick = () => {
	txt.setSelectionRange(2,2); // 设置起始点相同
	txt.focus();
}

const pos = {}
document.onmouseup = (ev) => {
   pos.start = txt.selectionStart;
   pos.end = txt.selectionEnd;
}
btn2.onclick = () => {
	txt.setSelectionRange(pos.start,pos.end)
	txt.focus();
}

btn3.onclick = () => {
	txt.setRangeText('❤️❤️❤️')
    txt.focus();
}

btn4.onclick = () => {
	txt.setRangeText('❤️❤️❤️',5,10,'preserve')
    txt.focus();
}
              
            
!
999px

Console