English 中文(简体)
修改表结构(合并单元)与格纳德
原标题:Modify table structure (merge cells) with jQuery

页: 1

<table>
<tr><td>9:00</td><td id= ts9 >task1</td></tr>
<tr><td>10:00</td><td id= ts10 ></td></tr>
<tr><td>11:00</td><td id= ts11 >task2</td></tr>
<tr><td>12:00</td><td id= ts12 >task3</td></tr>
</table>

并且由于任务需要2个小时,我需要将牢房与10和11个牢房合并起来。 我正在使用 j。

我认为:

$("#ts9").attr( colSpan , 2);

但它赢得了工作。

问题回答

如果你必须使用j Query,那么这项工作就是:

$( #ts10 )
    .text($( #ts11 ).text())
    .attr( rowspan , 2 )
    .closest( tbody )
    .find( #ts11 )
    .remove();​

。 JS Fiddle demo

或更简明扼要:

$( #ts10 )
    .text($( #ts11 ).remove().text())
    .attr( rowspan , 2 );​

JS Fiddle demo

略微增加......使用方法,将邻近各行的囚室与<代码>}2<<<>t/code>合并:

$( tr td.two ).each(
    function(){
        var that = $(this),
            next = that.parent().next().find( .two );
        if (next.length){
            that
                .text(next.remove().text())
                .attr( rowspan , 2 );
        }
    });

。 JS Fiddle demo

这为我工作。 Merges cell with same text:逻辑框架:对于每个囚室,如果是下个囚室,则拆除下个囚室、水泥col。 (注“colSpan”,而不是“colspan”——显然是一个浏览器问题)

$( #tblData tbody tr:first-child td ).each(function(){
 var colSpan=1;
 while( $(this).text() == $(this).next().text() ){
  $(this).next().remove();
  colSpan++;
 }
$(this).attr( colSpan ,colSpan);
});

您实际上需要从第二行中增加rowspan至ds10,然后增加remove ts11。 将你的代码从col子改为行文,添加如下内容:

$("#ts11").remove();

and you should get result you need. But i didn t personally try changing rowspan/colspan attributes via jquery, i m just assuming it works well. Hope it helps.

页: 1





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签