質問編集履歴
3
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,129 +1,132 @@
|
|
1
|
-
### 前提・実現したいこと
|
2
|
-
・選択ボタンをクリックされたものを選択済みのテーブルにデータを表示させるという動きを作成しているのですが、
|
3
|
-
一度選択ボタンをクリックされたメニューはボタンを非活性にし、
|
4
|
-
もし選択済みテーブルの解除ボタンをクリックしたら、クリックされたデータの選択ボタンを再度使用できるような作りをしたいのですが、
|
5
|
-
|
6
|
-
現在だと非活性はできるのですが、解除ボタンを押した際に、再度選択ボタンを使用できるようになっていません。
|
7
|
-
js初心者の為、データの移動等いいやり方が思いつきません。
|
8
|
-
皆様の知恵をお貸しいただきたいです。よろしくお願いいたします。
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
<tr>
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
<td
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
<td
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
<td
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
<div
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
<
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
let
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
let
|
84
|
-
|
85
|
-
|
86
|
-
newCell.
|
87
|
-
|
88
|
-
newCell
|
89
|
-
|
90
|
-
|
91
|
-
newCell.
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
input.
|
97
|
-
input.
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
input2.
|
104
|
-
input2.
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
let
|
114
|
-
|
115
|
-
|
116
|
-
let
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
1
|
+
### 前提・実現したいこと
|
2
|
+
・**選択ボタン**をクリックされたものを選択済みのテーブルにデータを表示させるという動きを作成しているのですが、
|
3
|
+
一度**選択ボタン**をクリックされたメニューはボタンを非活性にし、
|
4
|
+
もし選択済みテーブルの**解除ボタン(グレーのボタン)**をクリックしたら、クリックされたデータの**選択ボタン(緑色のボタン)**を再度使用できるような作りをしたいのですが、
|
5
|
+
|
6
|
+
現在だと非活性はできるのですが、解除ボタンを押した際に、再度選択ボタンを使用できるようになっていません。
|
7
|
+
js初心者の為、データの移動等いいやり方が思いつきません。
|
8
|
+
皆様の知恵をお貸しいただきたいです。よろしくお願いいたします。
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
### 該当のソースコード
|
14
|
+
|
15
|
+
```html
|
16
|
+
<div class="container table-responsive mb-3" style="max-height: 60vh; overflow-auto: scroll;">
|
17
|
+
<table class="table table-hover table-bordered">
|
18
|
+
<thead class="thead-light" style="position: sticky; top: 0; z-index: 1;">
|
19
|
+
<tr>
|
20
|
+
<th scope="col" class="text-center">選択</th>
|
21
|
+
<th scope="col" class="text-center">メニュー名</th>
|
22
|
+
<th scope="col" class="text-center">メニューCD</th>
|
23
|
+
</tr>
|
24
|
+
</thead>
|
25
|
+
<tbody>
|
26
|
+
<tr>
|
27
|
+
<td class="text-center"><button class="btn btn-success ml-2" type="button" onclick="selectStore(this)">選択</button></td>
|
28
|
+
<td>カレー</td>
|
29
|
+
<td>A11</td>
|
30
|
+
</tr>
|
31
|
+
<tr>
|
32
|
+
<td class="text-center"><button class="btn btn-success ml-2" type="button" onclick="selectStore(this)">選択</button></td>
|
33
|
+
<td>ハンバーグ</td>
|
34
|
+
<td>A12</td>
|
35
|
+
</tr>
|
36
|
+
<tr>
|
37
|
+
<td class="text-center"><button class="btn btn-success ml-2" type="button" onclick="selectStore(this)">選択</button></td>
|
38
|
+
<td>カツ丼</td>
|
39
|
+
<td>B3</td>
|
40
|
+
</tr>
|
41
|
+
<tr>
|
42
|
+
<td class="text-center"><button class="btn btn-success ml-2" type="button" onclick="selectStore(this)">選択</button></td>
|
43
|
+
<td>焼き魚</td>
|
44
|
+
<td>C1</td>
|
45
|
+
</tr>
|
46
|
+
</tbody>
|
47
|
+
</table>
|
48
|
+
</div>
|
49
|
+
|
50
|
+
<h5>選択済み店舗</h5>
|
51
|
+
<div class="container table-responsive" style="max-height: 60vh; overflow-auto: scroll;">
|
52
|
+
<table class="table table-hover table-bordered" id="targetTable">
|
53
|
+
<thead class="thead-light" style="position: sticky; top: 0; z-index: 1;">
|
54
|
+
<tr>
|
55
|
+
<th scope="col" class="text-center">解除</th>
|
56
|
+
<th scope="col" class="text-center">メニュー名</th>
|
57
|
+
<th scope="col" class="text-center">メニューCD</th>
|
58
|
+
</tr>
|
59
|
+
</thead>
|
60
|
+
<tbody>
|
61
|
+
</tbody>
|
62
|
+
</table>
|
63
|
+
</div>
|
64
|
+
```
|
65
|
+
```javaScript
|
66
|
+
<script type="application/javascript">
|
67
|
+
|
68
|
+
function selectStore(obj) {
|
69
|
+
|
70
|
+
let Row = obj.closest('tr')
|
71
|
+
let Cells = Row.getElementsByTagName("td")
|
72
|
+
let name = Cells[1].innerText
|
73
|
+
let code = Cells[2].innerText
|
74
|
+
this.newRow(name, code)
|
75
|
+
obj.disabled = true
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
function newRow(name, code) {
|
80
|
+
|
81
|
+
let table = document.getElementById('targetTable')
|
82
|
+
let newRow = table.insertRow()
|
83
|
+
let btn = newRow.insertCell(0)
|
84
|
+
newRow.innerHTML = '<td style="text-align: center;"><button class="btn btn-secondary ml-2 RowBtn" type="button" onclick="deleteStore(this)">解除</button></td>'
|
85
|
+
|
86
|
+
let newCell = newRow.insertCell(1)
|
87
|
+
let newText = document.createTextNode(name)
|
88
|
+
newCell.setAttribute("id", "selectName")
|
89
|
+
newCell.appendChild(newText)
|
90
|
+
|
91
|
+
newCell = newRow.insertCell(2)
|
92
|
+
newText = document.createTextNode(code)
|
93
|
+
newCell.setAttribute("id", "selectCd")
|
94
|
+
newCell.appendChild(newText)
|
95
|
+
|
96
|
+
const input = document.createElement("input")
|
97
|
+
input.setAttribute("type", "hidden")
|
98
|
+
input.setAttribute("name", "menu_name[]")
|
99
|
+
input.setAttribute("class", "menuName")
|
100
|
+
input.value = name
|
101
|
+
document.getElementById("inputForm").appendChild(input)
|
102
|
+
|
103
|
+
const input2 = document.createElement("input")
|
104
|
+
input2.setAttribute("type", "hidden")
|
105
|
+
input2.setAttribute("name", "menu_cd[]")
|
106
|
+
input2.setAttribute("class", "menuCd")
|
107
|
+
input2.value = code
|
108
|
+
document.getElementById("inputForm").appendChild(input2)
|
109
|
+
|
110
|
+
}
|
111
|
+
|
112
|
+
function deleteStore(obj) {
|
113
|
+
let tr = obj.parentNode.parentNode;
|
114
|
+
tr.parentNode.deleteRow(tr.sectionRowIndex);
|
115
|
+
|
116
|
+
let Row = obj.closest('tr')
|
117
|
+
let Cells = Row.getElementsByTagName("td")
|
118
|
+
let deletedMenuName = Cells[1].innerText
|
119
|
+
let deletedMenuCd = Cells[2].innerText
|
120
|
+
|
121
|
+
for (let element of [...document.getElementsByClassName('menuCd')]) {
|
122
|
+
if (element.value == deletedMenuName)
|
123
|
+
element.remove();
|
124
|
+
}
|
125
|
+
for (let element of [...document.getElementsByClassName('menuName')]) {
|
126
|
+
if (element.value == deletedMenuCd)
|
127
|
+
element.remove();
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
</script>
|
129
132
|
```
|
2
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
|
-
・
|
2
|
+
・選択ボタンをクリックされたものを選択済みのテーブルにデータを表示させるという動きを作成しているのですが、
|
3
|
-
一度
|
3
|
+
一度選択ボタンをクリックされたメニューはボタンを非活性にし、
|
4
|
-
もし選択済みテーブルの
|
4
|
+
もし選択済みテーブルの解除ボタンをクリックしたら、クリックされたデータの選択ボタンを再度使用できるような作りをしたいのですが、
|
5
5
|
|
6
6
|
現在だと非活性はできるのですが、解除ボタンを押した際に、再度選択ボタンを使用できるようになっていません。
|
7
7
|
js初心者の為、データの移動等いいやり方が思いつきません。
|
8
8
|
皆様の知恵をお貸しいただきたいです。よろしくお願いいたします。
|
9
9
|
|
10
|
-

|
11
|
-
|
12
|
-
|
13
|
-
|
14
10
|
### 該当のソースコード
|
15
11
|
|
16
12
|
```html
|
1
タグ追加しました
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|