簡體   English   中英

在特定表中查找所有TD的w /屬性(按ID)

[英]Find All TD's w/ attribute in Specific Table (by ID)

我正在使用Telerik的Kendo套件,並且需要對Scheduler小部件中的每個單元格進行檢查。 我通過搜索稱為“角色”的屬性並對它們進行.each來實現。 這很好用,但是如果我在頁面上有多個調度程序,我不想遍歷所有td ...只是在特定調度程序(內部是html表)中進行迭代。 我嘗試給調度程序指定ID,但選擇器似乎找不到任何td。 當我只使用(“ td [role = gridcell]”)。each都可以,但是會返回頁面中的所有td。 如果我嘗試添加所需的調度程序的ID,它將一無所獲。

var scheduler = $("#scheduler").data("kendoScheduler");
var view = scheduler.view();
view.table.find("#scheduler td[role=gridcell]").each(function (index, value)
{
    // Do checking here.
})

我確定選擇器中的語法存在問題,但我無法弄清楚。

find調用中不需要#scheduler選擇器。

 $("#scheduler").find("td[role=gridcell]").each(function (index, value) { $(value).css('color', 'red'); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table id="scheduler"> <tr> <td role="gridcell">A</td> <td role="gridcell">B</td> <td>C</td> <td>D</td> </tr> </table> <table id="test"> <tr> <td role="gridcell">A</td> <td role="gridcell">B</td> <td>C</td> <td>D</td> </tr> </table> 

在jQuery中,您應該能夠執行以下操作:

$("#scheduler td[role='gridcell']").each(function(index, elem) {
    // code here
});

注意:無需使用單獨的.find()操作,因為您可以將其全部放入選擇器中。

觀看演示: http : //jsfiddle.net/jfriend00/49Lg411h/

暫無
暫無

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

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