18
我有一個contenteditable
div和幾個段落。在contenteditable div中選擇範圍
這裏是我的代碼:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div id="main" contenteditable="true"
style="border:solid 1px black; width:300px; height:300px">
<div>Hello world!</div>
<div>
<br>
</div>
<div>This is a paragraph</div>
</div>
</body>
</html>
假設,我要做出選擇範圍將包含字符串「!世界這是」
如何做到這一點?
'removeAllRanges'然後'addRange'是我錯過了我的情況的作品。感謝代碼! – siannopollo 2017-01-16 18:39:07