回答編集履歴

1

質問文の追記コードに合わせて追加編集

2018/01/12 09:05

投稿

Tomak
Tomak

スコア1652

test CHANGED
@@ -22,49 +22,115 @@
22
22
 
23
23
 
24
24
 
25
+ **== 追記 ==**
26
+
27
+ 他の回答者の方からも私からも、実行したい`<script>`を一番最後(`</body>`の直前)に書いてくださいと言われていると思います。いちおう理由も書いたのですが。。。。
28
+
29
+ 別ファイルのソースにまとめようが、インラインに書こうが実行されるタイミングは一緒ですので、下記のように`</body>`直前に移動してください。(または`<html><head>..ここ..</head>`の部分に移動します)
30
+
31
+
32
+
25
33
  ```php
34
+
35
+ <!DOCTYPE html>
36
+
37
+ <html>
38
+
39
+ <head>
40
+
41
+ //...
42
+
43
+ </head>
44
+
45
+ <body>
46
+
47
+ //...
26
48
 
27
49
  <form name="フォーム名" id="test_info" action="..." method="post">
28
50
 
29
- //...
51
+ //...
30
52
 
53
+ <h3 class="Test_header">テスト</h3>
54
+
55
+ <table data-role="table" id="test_tab" data-mode="reflow" class="ui-responsive table-stroke">
56
+
31
- <table>
57
+ <thead>
58
+
59
+ <tr>
60
+
61
+ <th width="30%">名前</th>
62
+
63
+ <th width="30%">名</th>
64
+
65
+ <th width="30%">住所</th>
66
+
67
+ <th width="10%">削除</th>
68
+
69
+ </tr>
70
+
71
+ </thead>
72
+
73
+ <tbody id="test_tbody">
74
+
75
+ {assign var='i' value=0}
76
+
77
+
32
78
 
33
79
  <tr>
34
80
 
35
- <td>
81
+ <td>
36
82
 
37
- <select name="test_info" id="select_test_info" data-native-menu="true">
83
+ <select name="test_info" id="select_test_info" data-native-menu="true">
38
84
 
39
- <option value="">選択してください</option>
85
+ <option value="">選択してください</option>
40
86
 
41
- {section name=idx loop=$test_list}
87
+ {section name=idx loop=$test_list}
42
88
 
43
- <option value="{$test_list[idx].test_name|escape:"html"}"{if $test_list[idx].test_name == $test_list} selected{/if} data-disp="{$test_list[idx].test_d_name}" data-address="{$test_list[idx].test_address}">{$test_list[idx].test_name}</option>
89
+ <option value="{$test_list[idx].test_name|escape:"html"}"{if $test_list[idx].test_name == $test_list} selected{/if} data-disp="{$test_list[idx].test_d_name}" data-address="{$test_list[idx].test_address}">{$test_list[idx].test_name}</option>
44
90
 
45
- {/section}
91
+ {/section}
46
92
 
47
- </select>
93
+ </select>
48
94
 
49
- </td>
95
+ </td>
50
96
 
51
- <td><input type="text" name="test_d_name[{$i}]" value="{$test_list[idx1].test_d_name|escape:"html"}" placeholder="名" /></td>
97
+ <td><input type="text" name="test_d_name[{$i}]" value="{$test_list[idx1].test_d_name|escape:"html"}" placeholder="名" /></td>
52
98
 
53
- <td><input type="text" name="test_address[{$i}]" value="{$test_list[idx1].test_address|escape:"html"}" placeholder="住所" /></td>
99
+ <td><input type="text" name="test_address[{$i}]" value="{$test_list[idx1].test_address|escape:"html"}" placeholder="住所" /></td>
54
100
 
55
- <td><button type="button" id="btn_del_test{$i}" class="deleteTest ui-btn ui-shadow ui-corner-all ui-btn-icon-left ui-icon-delete">削除</button>
101
+ <td><button type="button" id="btn_del_test{$i}" class="deleteTest ui-btn ui-shadow ui-corner-all ui-btn-icon-left ui-icon-delete">削除</button>
56
102
 
57
103
  </tr>
58
104
 
59
- //...
105
+ </tbody>
60
106
 
61
- </table>
107
+ </table>
62
108
 
63
109
  </form>
64
110
 
65
111
 
66
112
 
113
+ //...
114
+
115
+
116
+
117
+ //↓↓↓↓↓↓↓ ここにJavaScript移動してみてください ↓↓↓↓↓↓↓↓
118
+
67
- <script type="text/javascript">
119
+ <script language="JavaScript" src="test.js?t={$smarty.now}"></script>
120
+
121
+ </body>
122
+
123
+ </html>
124
+
125
+ ```
126
+
127
+
128
+
129
+ `test.js`は下記のようにします。(下記は変更していません)
130
+
131
+
132
+
133
+ ```js
68
134
 
69
135
  console.log(document.getElementById('select_test_info'));
70
136
 
@@ -116,10 +182,4 @@
116
182
 
117
183
  }, false);
118
184
 
119
- </script>
120
-
121
- </body>
122
-
123
- </html>
124
-
125
185
  ```