简体   繁体   English

如何隐藏jquery中的第一列?

[英]How do I hide the first column in jquery?

I have a jquery/ajax that loads data from a csv file. 我有一个从csv文件加载数据的jquery / ajax。 What I'm trying to do is automatically hide the first column as the data is loaded in jquery and ajax. 我正在尝试做的是在将数据加载到jquery和ajax中时自动隐藏第一列。 I know you can do onclick function but would prefer it to automatically hide as the data loads. 我知道您可以执行onclick函数,但希望它在数据加载时自动隐藏。 How would I do this? 我该怎么做?

Here is the csv data: 这是csv数据:

ID,State,City,ZipCode 1,Florida,Tampa,33601 2,Ohio,Cleveland,55555 3,Indiana,Westfield,46032 ID,州,城市,邮政编码1,佛罗里达州坦帕市33601 2,俄亥俄州克利夫兰州55555 3印第安纳州韦斯特菲尔德,46032

Here is my code below: 这是我的代码如下:

    <!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
  <title>Parsing CSV Files</title>
  <script>

        (function($) {

  //$(document).ready(function() {

  'use strict';

  $.ajax({
    url: 'csv_data.csv',
    dataType: 'text',
  }).done(successFunction);

  function successFunction(data) {
    var allRows = data.split(/\r?\n|\r/);
    var table = '<table>';
    for (var singleRow = 0; singleRow < allRows.length; singleRow++) {
      if (singleRow === 0) {
        table += '<thead>';
        table += '<tr>';
      } else {
        table += '<tr>';
      }
      var rowCells = allRows[singleRow].split(',');
      var a = $('#test').text();
      document.getElementById("test").innerHTML = a;
      for (var rowCell = 0; rowCell < rowCells.length; rowCell++) {
        if (singleRow === 0) {
          table += '<th>';
          table += rowCells[rowCell];
          table += '</th>';
        } else if(rowCells[0]==a){
          table += '<td>';
          table += rowCells[rowCell];
          table += '</td>';
        }
      }
      if (singleRow === 0) {
        table += '</tr>';
        table += '</thead>';
        table += '<tbody>';
      } else {
        table += '</tr>';
      }
    }
    table += '</tbody>';
    table += '</table>';
    $('body').append(table);
  }

  // });

})(jQuery);
</script>
</head>

<body>
<pan id="test">2</span>
</body>

You want to hide the ID column? 您要隐藏ID列吗? Just ignore it in your loop and start with the second column: 只需在循环中忽略它,然后从第二列开始:

for (var rowCell = 1; rowCell < rowCells.length; rowCell++) {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM