【问题标题】:finding td count in a row of a table in iframe在 iframe 中的表格行中查找 td 计数
【发布时间】:2017-09-25 00:08:35
【问题描述】:

当我单击 iframe 中表格的表格单元格时,我希望能够找出一行中有多少个单元格,如果单元格是跨度,我希望能够将跨度用作细胞计数。

框架可以包含许多没有类的表,但我无法得到计数,它比应该的要高得多

iframe.find('td').click(function () {
            var thisCell = $(this);
            var thisRow = thisCell.closest('tr');
            var thisTbody = thisRow.closest('tbody');
            var thisTable = thisRow.closest('table');

            var url = "@(Html.Raw(Url.Action("_TableAttr")))";

            var d1 = $.Deferred();

            $.when(d1).then(function () {
                var tds = $(thisTable).children('tbody').children('tr').children('td').length;
                alert(tds);
            });

            d1.resolve(LoadNewsSideBarContent(url));

我尝试了一个循环遍历表的 .each 函数 > tbody> 行 > td 但仍然很奇怪。我觉得我在变量中存储表格的方式是错误的?

【问题讨论】:

    标签: jquery html iframe


    【解决方案1】:

    使用 JQuery,您可以在 thi 之类的元素中找到一个类型的所有元素:

     var listOfElements = $("#parentElementName").find("cell");
    

    这将返回父元素的所有单元格。 与使用 JavaScript 相比,您可以找到像这样的单元格数:

       var count = listOfElements.length;
    

    【讨论】:

    • 感谢回复,var listOfElements = $(thisRow).find("cell"); var count = listOfElements.length;警报(计数);返回 0
    • 我不确定 var thisRow = thisCell.closest('tr');返回点击的行。您是否尝试为您的行提供 ID?这样,您可以检查您是否在点击的行中搜索。
    • 我添加了一些代码来改变背景颜色,所有这些都排好了
    猜你喜欢
    • 2011-06-11
    • 2012-01-04
    • 2012-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-17
    相关资源
    最近更新 更多