【问题标题】:Start jquery each from 1从 1 开始每个 jquery
【发布时间】:2022-03-23 01:01:00
【问题描述】:
var nums = [];

$('#table_serv tr td.serv-nomer').each(function (elem, ind) {
    nums[parseInt($(this).text())] = elem;
    $(this).text(elem);
});

我需要从 1 开始每个elem。但是现在elem0 开始,可以是从1 开始。不同。如何从1 开始修复?

【问题讨论】:

标签: javascript jquery


【解决方案1】:

您可以使用not(':first') 从选择器中删除第一个元素:

$('#table_serv tr td.serv-nomer').not(':first').each(function (elem, ind) {

【讨论】:

    【解决方案2】:

    做吧

    var nums = [];
    
    $('#table_serv tr td.serv-nomer').each(function (elem, ind) {
        if(elem > 0 ) {
            nums[parseInt($(this).text())] = elem;
            $(this).text(elem);
        }
    });
    

    【讨论】:

      【解决方案3】:

      不包括第一个迭代或 0 索引处的元素:

      var nums = [];
      
          $('#table_serv tr td.serv-nomer').each(function (elem, ind) {
          if (elem != "0")
          {
              nums[parseInt($(this).text())] = elem;
              $(this).text(elem);
          }
          });
      

      或者,如果您只想迭代索引 1 处的项目,那么您可以这样做:

      var nums = [];
      
          $('#table_serv tr td.serv-nomer').each(function (elem, ind) {
          if (elem == 1)
          {
              nums[parseInt($(this).text())] = elem;
              $(this).text(elem);
          }
          });
      

      【讨论】:

        【解决方案4】:

        我希望以 1 而不是 0 开始数组

        $("a").each(function (i, e) {
        titles[i + 1] = $(this).text() })
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-06-27
          • 2016-04-18
          • 2014-07-05
          • 1970-01-01
          • 2016-06-01
          • 2016-10-05
          • 1970-01-01
          相关资源
          最近更新 更多