簡體   English   中英

使用javascript / jquery在表格中選擇元素

[英]Selecting elements within a table with javascript/jquery

我正在嘗試在表格內為每一行選擇一個ID。

這是我目前的表格(已通過瀏覽器檢查)。

<table id="sort">
            <thead>
                <tr>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th>Pri </th>
                </tr>
            </thead>

                        <tbody style="cursor: n-resize; " class="ui-sortable"><tr class="priorityRow">
                            <td id="tableDragSort">
                                <a class="deleteLink" href="#" rel="17904" title="">
                                 <img src="/Content/Images/Garage/DeleteButton.png"></a>
                            </td>
                            <td>
                                <img id="MainContent_MainColContent_ImageRepeater_CarImg_0" class="17904" src="" style="height:45px;width:60px;">
                            </td>
                            <td>
                                <input name="ctl00$ctl00$MainContent$MainColContent$ImageRepeater$ctl00$txtText" type="text" value="hjjj" id="MainContent_MainColContent_ImageRepeater_txtText_0">
                            </td>
                            <td class="picturePriority">
                                1
                            </td>
                        </tr><tr class="priorityRow" style="opacity: 1; z-index: 0; ">
                            <td id="tableDragSort" style="width: 22px; ">
                                <a class="deleteLink" href="#" rel="17903" title="">
                                 <img src="/Content/Images/Garage/DeleteButton.png"></a>
                            </td>
                            <td style="width: 60px; ">
                                <img id="MainContent_MainColContent_ImageRepeater_CarImg_1" class="17903" src="" style="height:45px;width:60px;">
                            </td>
                            <td style="width: 153px; ">
                                <input name="ctl00$ctl00$MainContent$MainColContent$ImageRepeater$ctl01$txtText" type="text" value="dd" id="MainContent_MainColContent_ImageRepeater_txtText_1">
                            </td>
                            <td class="picturePriority" style="width: 21px; ">
                                2
                            </td>
                        </tr><tr class="priorityRow" style="opacity: 1; z-index: 0; ">
                            <td id="tableDragSort" style="width: 22px; ">
                                <a class="deleteLink" href="#" rel="17895" title="">
                                 <img src="/Content/Images/Garage/DeleteButton.png"></a>
                            </td>
                            <td style="width: 60px; ">
                                <img id="MainContent_MainColContent_ImageRepeater_CarImg_2" class="17895" src="" style="height:45px;width:60px;">
                            </td>
                            <td style="width: 153px; ">
                                <input name="ctl00$ctl00$MainContent$MainColContent$ImageRepeater$ctl02$txtText" type="text" value="wggw" id="MainContent_MainColContent_ImageRepeater_txtText_2">
                            </td>
                            <td class="picturePriority" style="width: 21px; ">
                                3
                            </td>
                        </tr>
                  </table>

該ID在這里是179041790317895兩個<a rel=""><img class="">是一個我要選擇到我的JavaScript方法,它是在這里:

$("#sort .priorityRow").each(function ()
    {
        var index = $(this).index() + 1;


        var id = /* SELECT ID HERE */

        console.log(id);
        $(this).find(".picturePriority span").text(index);
        SetPicturePriority(id, index);
    });
}

只要它有效,我都不在乎我以哪種方式選擇ID。

有人能幫忙嗎? :)

你可以得到這樣的身份證

var id =$(this).attr("id");

聽起來您可能正在嘗試這樣做:

$("#sort .priorityRow").each(function () {
    var rel = $(this).find("a").first().attr("rel"),
        index = this.rowIndex + 1;

    $(this).find(".picturePriority").text(index);

    SetPicturePriority(rel, index);
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM