質問編集履歴
4
書式の改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -19,26 +19,4 @@
|
|
19
19
|
contenteditableを用いた、エディタを作成している際に、strongエレメントとtextノードが乱立してしまい。狙っている挙動(strongの取付取り外し)ができない場合が発生したため。
|
20
20
|
|
21
21
|
###試したこと
|
22
|
-
調べたとことnormalize()を使用することで回避できるとのことだったが、回避はできなかった
|
22
|
+
調べたとことnormalize()を使用することで回避できるとのことだったが、回避はできなかった
|
23
|
-
##これでうまくいきました
|
24
|
-
```javascript
|
25
|
-
const parent = document.getElementById("parent);
|
26
|
-
function normalize_string(){
|
27
|
-
parent.childNodes.forEach(function (currentValue, currentIndex, listObj) {
|
28
|
-
currentValue.childNodes.forEach(function (currentChildValue, currentChildIndex) {
|
29
|
-
for(let i = 0; i < currentValue.childNodes.length; i++){
|
30
|
-
for(let j = 1; j < currentValue.childNodes.length; j++){
|
31
|
-
if(currentValue.childNodes[i].className === "strong" && currentValue.childNodes[j].className === "strong" && i < j){
|
32
|
-
currentValue.childNodes[i].textContent = currentValue.childNodes[i].textContent + currentValue.childNodes[j].textContent;
|
33
|
-
currentValue.removeChild(currentValue.childNodes[j]);
|
34
|
-
break;
|
35
|
-
}
|
36
|
-
else{
|
37
|
-
break;
|
38
|
-
}
|
39
|
-
}
|
40
|
-
}
|
41
|
-
})
|
42
|
-
})
|
43
|
-
}
|
44
|
-
```
|
3
書式の改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -22,14 +22,12 @@
|
|
22
22
|
調べたとことnormalize()を使用することで回避できるとのことだったが、回避はできなかった
|
23
23
|
##これでうまくいきました
|
24
24
|
```javascript
|
25
|
+
const parent = document.getElementById("parent);
|
25
26
|
function normalize_string(){
|
26
|
-
|
27
|
+
parent.childNodes.forEach(function (currentValue, currentIndex, listObj) {
|
27
28
|
currentValue.childNodes.forEach(function (currentChildValue, currentChildIndex) {
|
28
29
|
for(let i = 0; i < currentValue.childNodes.length; i++){
|
29
30
|
for(let j = 1; j < currentValue.childNodes.length; j++){
|
30
|
-
console.log("zikkou");
|
31
|
-
console.log(i);
|
32
|
-
console.log(j);
|
33
31
|
if(currentValue.childNodes[i].className === "strong" && currentValue.childNodes[j].className === "strong" && i < j){
|
34
32
|
currentValue.childNodes[i].textContent = currentValue.childNodes[i].textContent + currentValue.childNodes[j].textContent;
|
35
33
|
currentValue.removeChild(currentValue.childNodes[j]);
|
2
書式の改善
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
連続する同じ要素をまとめる
|
1
|
+
連続する同じ要素をまとめる(解決済み)
|
body
CHANGED
@@ -19,4 +19,28 @@
|
|
19
19
|
contenteditableを用いた、エディタを作成している際に、strongエレメントとtextノードが乱立してしまい。狙っている挙動(strongの取付取り外し)ができない場合が発生したため。
|
20
20
|
|
21
21
|
###試したこと
|
22
|
-
調べたとことnormalize()を使用することで回避できるとのことだったが、回避はできなかった
|
22
|
+
調べたとことnormalize()を使用することで回避できるとのことだったが、回避はできなかった
|
23
|
+
##これでうまくいきました
|
24
|
+
```javascript
|
25
|
+
function normalize_string(){
|
26
|
+
editor.childNodes.forEach(function (currentValue, currentIndex, listObj) {
|
27
|
+
currentValue.childNodes.forEach(function (currentChildValue, currentChildIndex) {
|
28
|
+
for(let i = 0; i < currentValue.childNodes.length; i++){
|
29
|
+
for(let j = 1; j < currentValue.childNodes.length; j++){
|
30
|
+
console.log("zikkou");
|
31
|
+
console.log(i);
|
32
|
+
console.log(j);
|
33
|
+
if(currentValue.childNodes[i].className === "strong" && currentValue.childNodes[j].className === "strong" && i < j){
|
34
|
+
currentValue.childNodes[i].textContent = currentValue.childNodes[i].textContent + currentValue.childNodes[j].textContent;
|
35
|
+
currentValue.removeChild(currentValue.childNodes[j]);
|
36
|
+
break;
|
37
|
+
}
|
38
|
+
else{
|
39
|
+
break;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
})
|
44
|
+
})
|
45
|
+
}
|
46
|
+
```
|
1
書式の改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -13,4 +13,10 @@
|
|
13
13
|
4
|
14
14
|
<strong>5</strong>
|
15
15
|
```
|
16
|
-
としたい
|
16
|
+
としたい
|
17
|
+
|
18
|
+
###実現したい経緯
|
19
|
+
contenteditableを用いた、エディタを作成している際に、strongエレメントとtextノードが乱立してしまい。狙っている挙動(strongの取付取り外し)ができない場合が発生したため。
|
20
|
+
|
21
|
+
###試したこと
|
22
|
+
調べたとことnormalize()を使用することで回避できるとのことだったが、回避はできなかった
|