teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

8

誤記修正

2018/03/18 00:47

投稿

hh_ww
hh_ww

スコア22

title CHANGED
File without changes
body CHANGED
@@ -115,7 +115,7 @@
115
115
  function fncset_data(data) {
116
116
 
117
117
  try{
118
- alert($("#tbldata_yoyaku").index(data));
118
+ alert($("#table_id").index(data));
119
119
  alert('行:'+data.parentNode.rowIndex)
120
120
  alert('行:'+data.cellIndex)
121
121
  }catch( e ){

7

試したこと追記

2018/03/18 00:47

投稿

hh_ww
hh_ww

スコア22

title CHANGED
File without changes
body CHANGED
@@ -106,4 +106,20 @@
106
106
  var col = $("#table_id").cellIndex;
107
107
  alert(col);
108
108
  また、以下も同様でundefinedと出力されました。
109
- alert('行:'+this.parentNode.rowIndex+'列:'+this.cellIndex)
109
+ alert('行:'+this.parentNode.rowIndex+'列:'+this.cellIndex)
110
+
111
+ ・またまた試してみたこと
112
+ やはりうまくいかないのでhtml1.phpでonclickを使用し、onclick='fncset_data(this);'と記載しそれを受け取ったhtml2.phpのfncset_data内で受け取ったthisを使用し、以下のように処理してみましたが結果は-1,undefined,undefinedとなり行数は出力されませんでした。
113
+ 同記載すればよいのでしょうか?
114
+ ```
115
+ function fncset_data(data) {
116
+
117
+ try{
118
+ alert($("#tbldata_yoyaku").index(data));
119
+ alert('行:'+data.parentNode.rowIndex)
120
+ alert('行:'+data.cellIndex)
121
+ }catch( e ){
122
+ alert('err');
123
+ }
124
+ }
125
+ ```

6

試してみたこと追記

2018/03/18 00:46

投稿

hh_ww
hh_ww

スコア22

title CHANGED
File without changes
body CHANGED
@@ -101,7 +101,9 @@
101
101
 
102
102
  ```
103
103
 
104
- ・試してみたこと
104
+ 他にも試してみたこと
105
- html2.phpのclick(function() のなかで以下を実施してみましたが、なぜかundefineとエラーとなり行数が取得できませんでした。
105
+ html2.phpのclick(function() のなかで以下を実施してみましたが、なぜかundefinedとエラーとなり行数が取得できませんでした。
106
106
  var col = $("#table_id").cellIndex;
107
- alert(col);
107
+ alert(col);
108
+ また、以下も同様でundefinedと出力されました。
109
+ alert('行:'+this.parentNode.rowIndex+'列:'+this.cellIndex)

5

試してみたことを追記

2018/03/18 00:01

投稿

hh_ww
hh_ww

スコア22

title CHANGED
File without changes
body CHANGED
@@ -99,4 +99,9 @@
99
99
  });
100
100
  });
101
101
 
102
- ```
102
+ ```
103
+
104
+ ・試してみたこと
105
+ html2.phpのclick(function() のなかで以下を実施してみましたが、なぜかundefineとエラーとなり行数が取得できませんでした。
106
+ var col = $("#table_id").cellIndex;
107
+ alert(col);

4

指摘内容を反映

2018/03/17 23:55

投稿

hh_ww
hh_ww

スコア22

title CHANGED
File without changes
body CHANGED
@@ -66,4 +66,37 @@
66
66
  }
67
67
 
68
68
  }
69
+ ```
70
+
71
+
72
+ 提案していただいたように、テーブルの呼び元で行数を取得するようにしました。
73
+ 取得した行数を用いて、テーブルの値をtbl.rows[?].cells[?].innerText;などで取得します。
74
+
75
+ html1.php
76
+ ```
77
+ <table id="table_id" border="0" cellspacing="0" cellpadding="0">
78
+ <tr>
79
+ <th scope="col" class="f-weight" style="width:50px;">&nbsp;</th>
80
+ <th scope="col" width="220px" class="f-weight">データ1</th>
81
+ <th scope="col" width="120px" class="f-weight">データ2</th>
82
+ </tr>
83
+ <tr>
84
+ <td id='nyuuryoku' style='width:50px;' align='center'>
85
+ <input type='button' value='入力' /> </td>
86
+ <td>"._hs($CN->GetFieldData('aaaaa'))."</td>
87
+ <td>"._hs($CN->GetFieldData('bbbbb'))."</td>
88
+ </tr>
89
+ </table>
90
+ ```
91
+ html2.php(html1.phpの呼び元)
92
+
93
+ ```
94
+ $(document).ready(function () {
95
+ $("#table_id").click(function() {
96
+ alert($("td.nyuuryoku").index(this));
97
+ var value = tbl.rows[?].cells[?].innerText;
98
+ $("#data_name").val(value);
99
+ });
100
+ });
101
+
69
102
  ```

3

試した内容を追記

2018/03/17 16:21

投稿

hh_ww
hh_ww

スコア22

title CHANGED
File without changes
body CHANGED
@@ -37,4 +37,33 @@
37
37
  <td>"._hs($CN->GetFieldData('bbbbb'))."</td>
38
38
  </tr>
39
39
  </table>
40
+ ```
41
+
42
+ このようなパターンでも確認しています。
43
+ ```html1.php
44
+ <table id="table_id" border="0" cellspacing="0" cellpadding="0">
45
+ <tr>
46
+ <th scope="col" class="f-weight" style="width:50px;">&nbsp;</th>
47
+ <th scope="col" width="220px" class="f-weight">データ1</th>
48
+ <th scope="col" width="120px" class="f-weight">データ2</th>
49
+ </tr>
50
+ <tr>
51
+ <td id='nyuuryoku' style='width:50px;' align='center'>
52
+ <input type='button' onclick='fncset_data(0);' value='入力' /> </td>
53
+ <td>"._hs($CN->GetFieldData('aaaaa'))."</td>
54
+ <td>"._hs($CN->GetFieldData('bbbbb'))."</td>
55
+ </tr>
56
+ </table>
57
+ ```
58
+
59
+ ```html2.php(html1.phpの呼び元)
60
+ function fncset_data(data) {
61
+
62
+ try{
63
+ alert($("td.nyuuryoku").index(this));★-1が表示される
64
+ }catch( e ){
65
+ alert('err');
66
+ }
67
+
68
+ }
40
69
  ```

2

試したコードを追記しました。

2018/03/17 15:30

投稿

hh_ww
hh_ww

スコア22

title CHANGED
File without changes
body CHANGED
@@ -18,4 +18,23 @@
18
18
  <td>"._hs($CN->GetFieldData('bbbbb'))."</td>
19
19
  </tr>
20
20
  </table>
21
+ ```
22
+
23
+ 上記にも記載しておりますが、試してみたコードは以下のような内容です。
24
+ このように$("table_id").index(this)や数パターン試してもfncset_dataには-1しか返ってきませんでした。
25
+
26
+ ```html
27
+ <table id="table_id" border="0" cellspacing="0" cellpadding="0">
28
+ <tr>
29
+ <th scope="col" class="f-weight" style="width:50px;">&nbsp;</th>
30
+ <th scope="col" width="220px" class="f-weight">データ1</th>
31
+ <th scope="col" width="120px" class="f-weight">データ2</th>
32
+ </tr>
33
+ <tr>
34
+ <td style='width:50px;' align='center'>
35
+ <input name='nyuuryoku' type='button' id='nyuuryoku' onclick='fncset_data($("table_id").index(this));' value='入力' /> </td>
36
+ <td>"._hs($CN->GetFieldData('aaaaa'))."</td>
37
+ <td>"._hs($CN->GetFieldData('bbbbb'))."</td>
38
+ </tr>
39
+ </table>
21
40
  ```

1

追記

2018/03/17 14:04

投稿

hh_ww
hh_ww

スコア22

title CHANGED
File without changes
body CHANGED
@@ -1,6 +1,6 @@
1
1
  以下のような内容でnyuuryokuボタンが押されたらその行番号をパラメータとしてfncset_dataに渡したいです。
2
2
  ★部分に該当のボタンの行番号を入れるようにしたらよいのですが、
3
- rowIndexや$(this).parent()[0]などいろいろと調べた結果を入れても初めてのもので記載方法わからず行番号が出力されません。
3
+ rowIndexや$(this).parent()[0]や$("tr").index(this)などいろいろと調べた結果を★部分へ入れても-1入ってしまい行番号が出力されません。
4
4
  どのようにしたら渡せますでしょうか?
5
5
  環境はwindows10のIEとなります。
6
6