如何隐藏jquery中的第一列? [英] How do I hide the first column in jquery?

查看:91
本文介绍了如何隐藏jquery中的第一列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从csv文件加载数据的jquery/ajax.我正在尝试做的是在将数据加载到jquery和ajax中时自动隐藏第一列.我知道您可以执行onclick函数,但希望它在数据加载时自动隐藏.我该怎么做?

I have a jquery/ajax that loads data from a csv file. What I'm trying to do is automatically hide the first column as the data is loaded in jquery and ajax. I know you can do onclick function but would prefer it to automatically hide as the data loads. How would I do this?

这是csv数据:

ID,州,城市,邮政编码 1,佛罗里达州坦帕市33601 2,俄亥俄州克利夫兰55555 3,Indiana,Westfield,46032

ID,State,City,ZipCode 1,Florida,Tampa,33601 2,Ohio,Cleveland,55555 3,Indiana,Westfield,46032

这是我的下面的代码:

    <!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>

推荐答案

您要隐藏ID列?只需在循环中忽略它,然后从第二列开始:

You want to hide the ID column? Just ignore it in your loop and start with the second column:

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

这篇关于如何隐藏jquery中的第一列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆