简体   繁体   English

隐藏表格标题列

[英]hide table header column

I use jquery code to pull results for a search query on my website. 我使用jquery代码在我的网站上提取搜索查询的结果。 I would like to hide one of the table's column headers when the results appear. 结果出现时,我想隐藏表的列标题之一。 I have made the appropriate changes in HTML and the table appears correct when I go directly to the search results page, but if I refresh the search results page or pull a new query from that page, the table reverts back to the original text. 我已经对HTML进行了适当的更改,当我直接进入搜索结果页面时,该表显示正确,但是如果刷新搜索结果页面或从该页面中提取新查询,该表将还原为原始文本。

My question is, how do I adjust the jquery code to hide the column header text from appearing everytime it refreshes? 我的问题是,如何调整jQuery代码以隐藏每次刷新时都不会显示列标题文本?

Here is the jquery I am using 这是我正在使用的jQuery

jQuery('.loading').show();
var dataArr = {'region_id': region_id, 'from_date': from_date, 'to_date': to_date, 'course_no': course_no, 'course_id': course_id, 'gtr': gtr};
jQuery.ajax({
    url: Drupal.settings.basePath + "course/search/region/api",
    type: 'post',
    cache: false,
    datatype: 'json',
    data: dataArr,
    success: function (result) {
        jQuery('.loading').hide();
        var parsed = JSON.parse(result);
        //jQuery('.result_search_region').html(result.data);
        if (parsed.data.length > 0) {
            jQuery('.result_search_region').html(' ');
            jQuery('.result_search_region').append('<h5>Course Availability</h5>');
            jQuery('.result_search_region').append(parsed.data);
        } else {
            jQuery('.result_search_region').html(jQuery('#dt_no_schedule').html());
        }
    }
});

Here is the html I am using: 这是我正在使用的html:

<?php
    $schedule_in_arr = Direction_Session::get('schedule_id');
    $data_by_time = Direction_Session::get('data_by_time', array());
?>
<?php if (!empty($value['schedule_info'])): ?>
    <table class="jz-table jz-table-bordered jz-table-striped">
        <caption><?php echo $value['location_name']; ?></caption>
    <?php if (!empty($value['schedule_info'])): ?>
        <thead>
            <tr>
                <td>Start Date</td>
                <td class="alncenter">Duration</td>
                <td class="alncenter">Time</td>
                class="alncenter"></td>
                <td class="alncenter"></td>
            </tr>
        </thead>
        <tbody>

It seems a little unclear do want to remove the head once you get the data (might be a poor user experience), or are you getting multiple headers shown? 似乎有点不清楚,是要在获取数据后删除磁头(可能是不良的用户体验),还是要显示多个标头?

To hide the thead figure out where/when you want to hide the header with this: 要将主题图隐藏在想要隐藏标题的位置/时间,请执行以下操作:

  var elem = $("thead");  
  elem.css('visibility', 'hidden');  

Or if you keep getting multiple: 或者,如果您不断增加:
table
thead Thead
thead Thead
... ...

Then I'd suggest the DOM node you're updating/replacing isn't correct. 然后,我建议您要更新/替换的DOM节点不正确。 I'd suggest you look at replacing the tbody alone on update and get remove the thead in the html your graft in. One thing about the code, as someone that needs to test stuff alot, where are the ID's on your elements, make everyone's life easier.... :) 我建议您考虑在更新时单独替换tbody,并在移植的html中删除thead。关于代码的一件事,因为有人需要大量测试东西,所以您的元素上有ID,使每个人都生活更轻松.... :)

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

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