繁体   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