为什么我的thead没有出现在Internet Explorer中?

men*_*mam 2 html javascript internet-explorer dom

我用thead(标题)制作了一张桌子; 在Mac和Firefox上一切都很好,但在Internet Explorer 6上,头部已经消失......

知道为什么吗?

以下是测试它的链接:http://www.acecrodeo.com/new/05-rodeos.php ...该表构建于tablerize.js:

jQuery.fn.tablerize = function() {
    return this.each(function() {
        var table;
        $(this).find('li').each(function(i) {
            var values = $(this).html().split('*');
            if(i == 0) {
                table = $('<table>');
                var thead = $('<thead>');
                $.each(values, function(y) {
                    thead.append($('<th>').html(values[y]));
                });
                table.append(thead);
            } else {
               var tr = $('<tr>');
               $.each(values, function(y) {
                   tr.append($('<td>').html(values[y]));
               });
               table.append(tr);
            }
        });
        $(this).after(table).remove();
    });
};
Run Code Online (Sandbox Code Playgroud)

...从页面上的列表:

<ul>

<li>&nbsp; Date*Endroit*Sanction</li>
<li>&nbsp; 29 Mars &amp; 5 Avril*St-&Eacute;variste, Beauce&nbsp; # 1*&Eacute;quipe Rod&eacute;o du Qc.</li>
<li>&nbsp; 12 &amp; 19 Avril*St-&Eacute;variste, Beauce&nbsp; # 2*&Eacute;quipe Rod&eacute;o du Qc.</li>
<!-- ... -->
</ul>
Run Code Online (Sandbox Code Playgroud)

Sho*_*og9 6

<th>直接在<thead>组中包含元素; 这实际上并不合法.你必须将它们包含在一个<tr>元素中,并把放在<thead>...中

请参阅:11.2.3行组:THEAD,TFOOT和TBODY元素

因此,修改jQuery.fn.tablerize()插入<tr><thead>追加前<th>元素:

table = $('<table>');
var thead = $('<thead>');
var headRow = $('<tr>');
$.each(values, function(y) {
      headRow.append($('<th>').html(values[y]));
   });
thead.append(headRow);
table.append(thead);
Run Code Online (Sandbox Code Playgroud)

请注意,您也省略了该<tbody>元素; 你应该把剩下的行放在其中一行中.


Pao*_*ino 5

好吧,因为我是tablerize的作者,我不妨解决它.

jQuery.fn.tablerize = function() {
    return this.each(function() {
        var table = $('<table>');
        var tbody = $('<tbody>');
        $(this).find('li').each(function(i) {
            var values = $(this).html().split('*');
            if(i == 0) {
                var thead = $('<thead>');
                var tr = $('<tr>');
                $.each(values, function(y) {
                    tr.append($('<th>').html(values[y]));
                });
                table.append(thead.append(tr));
            } else {
               var tr = $('<tr>');
               $.each(values, function(y) {
                   tr.append($('<td>').html(values[y]));
               });
               tbody.append(tr);
            }
        });
        $(this).after(table.append(tbody)).remove();
    });
};
Run Code Online (Sandbox Code Playgroud)

应该这样做.