回答編集履歴

1

chousei

2019/11/11 03:55

投稿

yambejp
yambejp

スコア114850

test CHANGED
@@ -1,3 +1,59 @@
1
1
  contenteditableはブラウザによって実装が違うのでめんどくさい調整をする気がないなら
2
2
 
3
3
  すなおにtextareaでやった方がよいですよ
4
+
5
+
6
+
7
+ # sample
8
+
9
+ 以下moを利用した検証
10
+
11
+ ```javascript
12
+
13
+ <style>
14
+
15
+ .txt-area{
16
+
17
+ background: lightgray;
18
+
19
+ line-height: 30px;
20
+
21
+ font-size: 20px;
22
+
23
+ height:30px;
24
+
25
+ width:200px;
26
+
27
+ border: 2px solid;
28
+
29
+ border-color: #1da1f2;
30
+
31
+ }
32
+
33
+ </style>
34
+
35
+ <script>
36
+
37
+ const observer = new MutationObserver((mutations) => {
38
+
39
+ mutations.forEach((mutation) => {
40
+
41
+ console.log(mutation.target.innerHTML);
42
+
43
+ });
44
+
45
+ });
46
+
47
+ const config = { childList:true};
48
+
49
+ window.addEventListener('DOMContentLoaded', ()=>{
50
+
51
+ observer.observe(document.querySelector('#dmComposerTextInput'), config);
52
+
53
+ });
54
+
55
+ </script>
56
+
57
+ <div aria-multiline="true" class="txt-area" contenteditable="true" id="dmComposerTextInput" role="textbox" spellcheck="true" tabindex="0" style="outline: none; user-select: text; white-space: pre-wrap; overflow-wrap: break-word;"></div>
58
+
59
+ ```