浏览器F12 console 输入
- document.body.contentEditable='true';
return "true"
则表示,开启网页文字编辑状态,可随意在网页上编辑任何标签内的文字了,省去了鼠标 反复查找元素的方法。
::before 伪元素内的文字除外。
编辑完后关闭状态 console 输入
- document.body.contentEditable='false';
return "false"
则表示,编辑状态已关闭。
contenteditable 属性为枚举 类型,表示元素是否可被用户编辑。如果可以,浏览器会修改元素的部件以允许使用者编辑。
以下这段英语在正常状态下可随意编辑:
Our destiny offers not the cup of despair,but the chalice of opportunity.So let us seize it,not in fear,but in gladness.
—— R.M. Nixon.
Chrome | Edge | Firefox | IE | Opera | Safari | Android webview | Chrome for Android | Firefox for Android | Opera for Android | Safari on iOS | Samsung Internet | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
contenteditable | ✓ | 12 | 3 | 5.5 | 9 | ✓ | ✓ | ✓ | 4 | ✓ | ✓ | ✓ |
contenteditable="caret" | ✓ | ≤79 | ✗ | ✗ | ✓ | ✗ | ✓ | ✓ | ✗ | ✓ | ✗ | ✓ |
contenteditable="events" | ✓ | ≤79 | ✗ | ✗ | ✓ | ✗ | ✓ | ✓ | ✗ | ✓ | ✗ | ✓ |
contenteditable="plaintext-only" | ✓ | ≤79 | ✗ | ✗ | ✓ | ✓ | ✓ | ✓ | ✗ | ✓ | ✓ | ✓ |
contenteditable="typing" | ✓ | ≤79 | ✗ | ✗ | ✓ | ✗ | ✓ | ✓ | ✗ | ✓ | ✗ | ✓ |