<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <div contenteditable="true" id="guestbook_editor">2</div> <button onclick="set_focus()">aa</button> <script> function set_focus() { var el=document.getElementById('guestbook_editor'); var range = document.createRange(); range.selectNodeContents(el); range.collapse(false); var sel = window.getSelection(); sel.removeAllRanges(); sel.addRange(range); } </script> </body> </html>
我看不太懂,额,原文地址:
https://www.cnblogs.com/jonie-wong/p/5519822.html
来源:https://www.cnblogs.com/woyujiezhen/p/12588808.html