如何使用jQuery将有限值插入到html表的每一行中

时间:2021-05-08 14:31:13

var intmob = [];
var strmob;

$(document).ready(function() {

  strmob = "1234567891,2453434523, 2345645643,4565464674,5901205466, 5234345516,2467284567,5343452891,5464667891,1234567891,5465284566,1234567891,1234567891, 1234567891, 1234567891, 1234567891";
  mob();
});

function mob() {
  var strArr = strmob.split(',');
  //intmob = [];
  for (i = 0; i < strArr.length; i++)
    intmob.push(parseInt(strArr[i]));
  return intmob;
}

function insertmo() {
  for (var i = 0; i < intmob.length; i++) {
    var t1 = intmob[0][0];
    var t2 = intmob[0][1];
    var t3 = intmob[0][2];
    var t4 = intmob[0][3];
    var t5 = intmob[0][4];
    var t6 = intmob[0][5];
    var t7 = intmob[0][6];

    $("#mo_1").text(t1);
    $("#mo_2").text(t2);
    $("#mo_3").text(t3);
    $("#mo_4").text(t4);
    $("#mo_5").text(t5);
    $("#mo_6").text(t6);
    $("#mo_7").text(t7);
  }
}

<table id="tbl" class="tbl1">
  <tr>
    <th>
      mobileno
    </th>
    <td>
    </td>
  </tr>
  <tr>
    <th>
      mobileno
    </th>
    <td id="Fo_1">
    </td>
  </tr>
  <tr>
    <th>
      mobileno
    </th>
    <td id="Fo_2">
    </td>
  </tr>
  <tr>
    <th>
      mobileno
    </th>
    <td id="Fo_3">
    </td>
  </tr>
  <tr>
    <th>
      mobileno
    </th>
    <td id="Fo_4">
    </td>
  </tr>
  <tr>
    <th>
      mobileno
    </th>
    <td id="Fo_5">
    </td>
  </tr>
</table>

How to insert limited values of array into each row of HTML table. Here I want that minimum one value and maximum 3 values can be insert each row of HTML table if one row had max 3 values than other value should go to next row of HTML table.so how can i achieve this. I am new to jQuery

如何将有限的数组值插入HTML表的每一行。在这里,我希望最少一个值和最多3个值可以插入HTML表的每一行,如果一行有最多3个值,那么其他值应该转到HTML表的下一行。所以我该如何实现这一点。我是jQuery的新手

1 个解决方案

#1


1  

You can use the following script to divide your values and populate the table rows :

您可以使用以下脚本划分值并填充表行:

var strmob = "1234567891,2453434523,2345645643,4565464674,5901205466,5234345516,2467284567,5343452891";

var arrmob = strmob.split(",");

$('#tbl td').each(function(i) {
  var arrsub = arrmob.splice(0, 3);
  $(this).text(arrsub.join(';'));
});

Complete example based on your code :

基于您的代码的完整示例:

JSFIDDLE

#1


1  

You can use the following script to divide your values and populate the table rows :

您可以使用以下脚本划分值并填充表行:

var strmob = "1234567891,2453434523,2345645643,4565464674,5901205466,5234345516,2467284567,5343452891";

var arrmob = strmob.split(",");

$('#tbl td').each(function(i) {
  var arrsub = arrmob.splice(0, 3);
  $(this).text(arrsub.join(';'));
});

Complete example based on your code :

基于您的代码的完整示例:

JSFIDDLE