0

私の現在の読み取りは、forループにあるにもかかわらず、実行された最初の行のデータピッカーのみを表示します。私のjqueryは強力ではありませんが、それが私の問題だと思います。

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <script src="jquery.js" type="text/javascript"></script>
<script src="jquery.maskedinput.js" type="text/javascript"></script>
 <script>
  $(function() {
    $( "#datepicker" ).datepicker()
    $( "#format" ).change(function() {
      $( "#datepicker" ).datepicker( "option", "dateFormat", $( this ).val() );
    });
  });
  </script>

これは私のコードの html にすぎません。これにクラスを追加する必要があるかもしれませんが、jquery が ID に基づいてコードを実行するかどうかは問題ではありません。

                <tr>
                <th><input type="checkbox" id="selectall"/>   Check All</th>
                    <th>Rootname </th>
                    <td>Urls</td>
                    <th>custs </th>
                    <th> jvmms </th>
                    <th>x64 </th>
                    <th>currentplatform </th>
                    <th> currentjdk </th>
                    <th>currenttomcat </th>
                    <th>Time </th>
                    <th>Date </th>
                </tr>
                    {% for status in root %}
                <tr>
                <td align="center"><input type="checkbox" class="case" name="case"></td>
                    <td>{{ status.rootname }}</td>
                    <td>{{ status.urls }}</td>
                    <td>{{ status.custs }}</td>
                    <td> {{ status.jvmms }}</td>
                    <td>{{ status.x64 }}</td>
                    <td>{{ status.currentplatform }}</td>
                    <td> {{ status.currentjdk }}</td>
                    <td>{{ status.currenttomcat }}</td>
                    <td><p> <input type="text" class="pick" id="datepicker" size="25" /></p></td>
                            <td>
                <input type="text" value="12:00" size="3" />
                <select name="ampm">
                    <option value="am">AM</option>
                    <option value="pm">PM</option>
                </select></td>


                </tr>

                    {% endfor %}

            </table>
4

2 に答える 2

0

要素 ID ではなく、クラスに jquery コードを適用する必要があります。

$(".pick").datepicker();
$("#format").change(function() {
      $(".pick").datepicker("option", "dateFormat", $(this).val());
});

id と class の違いは、class はページで繰り返し使用できますが、id は 1 回しか使用できないことです。そのため、id セレクターに関数をアタッチすると、一度だけ使用されます。

于 2013-07-08T21:08:58.627 に答える
0

クラスに関するマティーノの発言はもちろん正しかったのですが、django を使用する場合は、html 内にも forloop.counter を追加するだけで済みます。

**$(".pick").datepicker();
$("#format").change(function() {
  $(".pick").datepicker("option", "dateFormat", $(this).val());
    });**

<td> <p class= "selector"> <input type="text" class="pick" id="datepick **{{forloop.counter}}**" size="25"  /> </p> </td>
                        <td>
于 2013-07-09T13:44:58.733 に答える