質問編集履歴

1

質問内容が本題とは異なっていた

2018/01/31 08:57

投稿

Qoo
Qoo

スコア1249

test CHANGED
File without changes
test CHANGED
@@ -1,209 +1,161 @@
1
- お世話になっておりま
1
+ 前回の質問ではエンターキー押下でsubmitが発生しいたようで、js以前の不具合が発生しておりました。
2
2
 
3
- 以下のLISTVIEWに、Javascriptにzaikosu(テキスト)+ order1Text(ラベル)の結果をzaikoAjtLabel(ラベル)にセットしたいので
3
+ 質問を変更させ頂きま
4
4
 
5
+
6
+
7
+ asp.net ListViewで生成されたテーブル上で、Javascript(jquery)を用いて
8
+
5
- ようにすればよいでしょうか
9
+ 各項目の計算を行たい
10
+
11
+
12
+
13
+ 画面描画後、生成されたHTMLは以下の通りでした。
14
+
15
+
16
+
17
+ ```HTML
18
+
19
+ <table id="itemPlaceholderContainer" border="0" >
20
+
21
+ <tbody>
22
+
23
+
24
+
25
+ <tr style="">
26
+
27
+ <th >商品</th>
28
+
29
+ <th >規格</th>
30
+
31
+ <th >在庫数</th>
32
+
33
+ <th >調整数</th>
34
+
35
+ <th >調整後在庫</th>
36
+
37
+ </tr>
38
+
39
+
40
+
41
+ <tr>
42
+
43
+ <td >
44
+
45
+ <span id="itemLabel">アイテム1</span>
46
+
47
+ </td>
48
+
49
+ <td >
50
+
51
+ <span id="lotLabel">大</span>
52
+
53
+ </td>
54
+
55
+ <td >
56
+
57
+ <span id="order1Label">20</span>
58
+
59
+ </td>
60
+
61
+ <td >
62
+
63
+ <input name="ctl00$ContentPlaceHolderContent$_listView$ctrl0$order1Text" type="text" value="0" id="order1Text">
64
+
65
+ </td>
66
+
67
+ <td >
68
+
69
+ <span id="zaikoAjtLabel">0</span>
70
+
71
+ </td>
72
+
73
+ </tr>
74
+
75
+
76
+
77
+ <tr>
78
+
79
+ <td >
80
+
81
+ <span id="itemLabel">アイテム1</span>
82
+
83
+ </td>
84
+
85
+ <td >
86
+
87
+ <span id="lotLabel">小</span>
88
+
89
+ </td>
90
+
91
+ <td >
92
+
93
+ <span id="order1Label">10</span>
94
+
95
+ </td>
96
+
97
+ <td >
98
+
99
+ <input name="ctl00$ContentPlaceHolderContent$_listView$ctrl1$order1Text" type="text" value="0" id="order1Text">
100
+
101
+ </td>
102
+
103
+ <td >
104
+
105
+ <span id="zaikoAjtLabel">0</span>
106
+
107
+ </td>
108
+
109
+ </tr>
110
+
111
+
112
+
113
+ </tbody>
114
+
115
+ </table>
116
+
117
+ ```
118
+
119
+
120
+
121
+ 処理としては、input(id=order1Text)が変更されたときに計算させたかったので
122
+
123
+ 下記のようなjqueryを作成しました。ですが、同じidが複数存在することなり、1行目は反応しますが、2行目が反応しません。
124
+
125
+
126
+
127
+ ```jquery
128
+
129
+ $('#order1Text').change(function () {
130
+
131
+ alert('値が変更された');
132
+
133
+ });
134
+
135
+ ```
136
+
137
+
138
+
139
+ そこでセレクタをidではなく、name属性にしようと思ったのですが、
140
+
141
+ ASP.netではclientidmode="Static"を使用しても、nameは固定できないようなのです。
142
+
143
+
144
+
145
+ 考えた結果、input属性の変更を検知して、name属性を取得し、テーブル全行からnameが含まれる行を取得して
146
+
147
+ その行にあるフィールドを取得して計算させようかと思ったのですが、もっと簡単にできるような方法はないのでしょうか。
148
+
149
+
150
+
151
+ $('input').change(function () {
152
+
153
+ alert(this.name);
154
+
155
+ });
6
156
 
7
157
 
8
158
 
9
159
 
10
160
 
11
-
12
-
13
- ```ここに言語を入力
14
-
15
- <div id="scr_pnl" runat="server">
16
-
17
-
18
-
19
- <asp:ListView ID="listView " runat="server" DataSourceID="MySqlDataSource" DataKeyNames="syouhin" >
20
-
21
-
22
-
23
- <EmptyDataTemplate>
24
-
25
- <table id="Table1" runat="server" style="">
26
-
27
- <tr>
28
-
29
- <td>データは返されませんでした。</td>
30
-
31
- </tr>
32
-
33
- </table>
34
-
35
- </EmptyDataTemplate>
36
-
37
-
38
-
39
- <ItemTemplate>
40
-
41
-
42
-
43
- <tr>
44
-
45
-
46
-
47
- <td >
48
-
49
- <asp:Label Text='<%# Eval("syouhin") %>' runat="server" ID="itemLabel" />
50
-
51
- </td>
52
-
53
-
54
-
55
- <td >
56
-
57
- <asp:Label Text='<%# Eval("zaikosu") %>' runat="server" ID="order1Label" Width="80" />
58
-
59
- </td>
60
-
61
-
62
-
63
- <td >
64
-
65
- <asp:TextBox ID="order1Text" runat="server" Text="0" Width="80"></asp:TextBox>
66
-
67
- </td>
68
-
69
-
70
-
71
- <td >
72
-
73
- <asp:Label Text='0' runat="server" ID="zaikoAjtLabel" Width="80" />
74
-
75
- </td>
76
-
77
-
78
-
79
- <td >
80
-
81
- <asp:DropDownList ID="DropDownList1" runat="server" "></asp:DropDownList>
82
-
83
- </td>
84
-
85
-
86
-
87
- </tr>
88
-
89
- </ItemTemplate>
90
-
91
-
92
-
93
- <LayoutTemplate>
94
-
95
-
96
-
97
- <table border="0" class="table table-bordered table-hover table-striped table-hgroup" styke="width:90%;" _fixedhead="rows:1; cols:4">
98
-
99
- <tr runat="server" style="">
161
+ ASP.netよりJavascript寄りの質問かもしれませんが、どうぞよろしくお願い致します。
100
-
101
- <th runat="server" >商品</th>
102
-
103
- <th runat="server" >在庫数</th>
104
-
105
- <th runat="server" >調整数</th>
106
-
107
- <th runat="server" >調整後在庫</th>
108
-
109
- <th runat="server" >調整理由</th>
110
-
111
- </tr>
112
-
113
-
114
-
115
-
116
-
117
- <asp:PlaceHolder runat="server" ID="itemPlaceholder" />
118
-
119
-
120
-
121
- </table>
122
-
123
-
124
-
125
- </LayoutTemplate>
126
-
127
-
128
-
129
- <SelectedItemTemplate>
130
-
131
- <tr>
132
-
133
-
134
-
135
- <td >
136
-
137
- <asp:Label Text='<%# Eval("syouhin") %>' runat="server" ID="itemLabel" />
138
-
139
- </td>
140
-
141
- <td >
142
-
143
- <asp:Label Text='<%# Eval("zaikosu") %>' runat="server" ID="order1Label" />
144
-
145
- </td>
146
-
147
-
148
-
149
- <td >
150
-
151
- <asp:TextBox ID="order1Text" runat="server" Text="0" ></asp:TextBox>
152
-
153
- </td>
154
-
155
-
156
-
157
- <td >
158
-
159
- <asp:Label Text='0' runat="server" ID="zaikoAjtLabel" Width="80" />
160
-
161
-
162
-
163
- </td>
164
-
165
- <td >
166
-
167
- <asp:DropDownList ID="DropDownList1" runat="server" "></asp:DropDownList>
168
-
169
- </td>
170
-
171
-
172
-
173
- </tr>
174
-
175
- </SelectedItemTemplate>
176
-
177
-
178
-
179
- </asp:ListView>
180
-
181
- ```
182
-
183
-
184
-
185
-
186
-
187
- 下記のJSでテストしてみましたが、アラートは表示されず
188
-
189
- 無効なポストバックまたはコールバック引数です。
190
-
191
- イベントの検証は、構成の <pages enableEventValidation="true"/>、
192
-
193
- またはページの <%@ Page EnableEventValidation="true" %> を使用して有効にされます。
194
-
195
- と表示されてしまいます。
196
-
197
-
198
-
199
-
200
-
201
- $(function () {
202
-
203
- $("order1Text").keypress(function (e) {
204
-
205
- alert('テキストボックス上でエンターキーが押されました');
206
-
207
- });
208
-
209
- }