<!doctype html> <body> <p id="p">Select me: <i>italic</i> and <b>bold</b></p> <script> // 从 <p> 的第 0 个子节点选择到最后一个子节点 document.getSelection().setBaseAndExtent(p, 0, p, p.childNodes.length); </script> </body>