1

こんにちは私のシステムは、親のリストを含む春のmavenプロジェクトで構成されており、 th: timeleafテンプレートエンジンを使用してhtmlページに表示されます 。問題は、最初のボタンでのみ機能することです。私が試したボタンの残りの部分は機能しません以下のコード

脚本

$(document).ready(function(){
              $("#button").attr("name").click(function(){
                  alert($(this).attr("name"));

              });
            });

タイムリーフ反復子を持つテーブル

<table class="table">

            <tr>
                <th>Parent Name</th>
                <!-- <th>Country</th> -->
                <!-- <th>State</th>
                        <th>District</th> -->

                <th>Address</th>
                <th>Phone No</th>
                <th>Email</th>

                <th>Active/Inactive</th>
                <th></th>
            </tr>
            <tr th:each=" parent : ${parentList}">
                <td th:text="${parent.parentName}"></td>
                <!-- <td  th:text="${parent.district.state.country.countryName}"></td> -->
                <!--    <td  th:text="${parent.district.state.stateName}"></td>
                            <td  th:text="${parent.district.districtName}"></td> -->
                <td th:text="${parent.parentAddress}"></td>
                <td th:text="${parent.parentPhone}"></td>
                <td th:text="${parent.parentEmail}"></td>


                <td><a id="button" href="#" class="btn btn-small"
                    th:value="${parent.id}" th:name="${parent.id}" th:text="${parent.id}"></a></td>
            </tr>


        </table>
4

2 に答える 2

2

コードにはいくつかの問題があります。まず、ボタンに #ID を使用しています。これは、.button などのクラスである必要があります。

次に、セレクターとクリックの間の属性が少し奇妙です。次のコードを試してください

  $(".button").click(function(){
       alert($(this).attr("name"));
  });

jQuery は、一致した要素を暗黙的に反復します。

お役に立てれば!

于 2013-10-11T06:27:12.757 に答える
0

$("#button").attr("名前")

attr の名前のみを指定します。次の参照を取得してみてください

http://api.jquery.com/category/selectors/attribute-selectors/

于 2013-10-11T06:25:51.967 に答える