回答編集履歴
2
chousei
test
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
target.addEventListener('focus',()=>{
|
18
18
|
|
19
|
-
r=document.createRange();
|
19
|
+
const r=document.createRange();
|
20
20
|
|
21
21
|
r.setStart(target,0);
|
22
22
|
|
1
sample
test
CHANGED
@@ -1,3 +1,35 @@
|
|
1
1
|
contenteditableな要素は入れ子を持つ可能性があるため単純には
|
2
2
|
|
3
3
|
範囲選択はできません
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
# sample
|
8
|
+
|
9
|
+
```javascript
|
10
|
+
|
11
|
+
<script>
|
12
|
+
|
13
|
+
window.addEventListener('DOMContentLoaded', ()=>{
|
14
|
+
|
15
|
+
const target=document.querySelector('#target');
|
16
|
+
|
17
|
+
target.addEventListener('focus',()=>{
|
18
|
+
|
19
|
+
r=document.createRange();
|
20
|
+
|
21
|
+
r.setStart(target,0);
|
22
|
+
|
23
|
+
r.setEnd(target,1);
|
24
|
+
|
25
|
+
window.getSelection().addRange(r);
|
26
|
+
|
27
|
+
});
|
28
|
+
|
29
|
+
});
|
30
|
+
|
31
|
+
</script>
|
32
|
+
|
33
|
+
<div id="target" contenteditable="true">文字を入力</div>
|
34
|
+
|
35
|
+
```
|