Javascript学習ノートpart 1(Tableセルと同じデータが自動的に結合されます)

23482 ワード



<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>        title>

    <script type="text/javascript">
        window.onload =function  () {
            var tab=document.getElementById(table1);
            var  maxCol= 6,val, count, start;  //maxCol:           
            for(var col = maxCol-1; col >= 0 ; col--) {
                count = 1;
                val = "";
                for(var i=0; iif(val == tab.rows[i].cells[col].innerHTML) {
                        count++;
                    } else {
                        if (count > 1) {
                            //  
                            start = i - count;
                            tab.rows[start].cells[col].rowSpan = count;
                            for(var j=start+1; j"none";
                            }
                            count = 1;
                        }
                        val = tab.rows[i].cells[col].innerHTML;
                    }
                }

                if(count > 1 ) {
                    //  ,          
                    start = i - count;
                    tab.rows[start].cells[col].rowSpan = count;
                    for(var j=start+1; j"none";
                    }
                }
            }
        };
    script>

head>
<body><table width="400" border="1">
    <tr>
        <td>atd>
        <td>1td>
        <td>2td>
        <td>3td>
        <td>4td>
        <td>5td>
    tr>
    <tr>
        <td>atd>
        <td>1td>
        <td>2td>
        <td>3td>
        <td>4td>
        <td>6td>
    tr>
    <tr>
        <td>atd>
        <td>2td>
        <td>3td>
        <td>3td>
        <td>4td>
        <td> td>
    tr>
    <tr>
        <td>btd>
        <td>3td>
        <td>4td>
        <td>6td>
        <td>7td>
        <td> td>
    tr>
    <tr>
        <td>btd>
        <td>3td>
        <td>5td>
        <td>6td>
        <td>7td>
        <td> td>
    tr>
    <tr>
        <td>cctd>
        <td>2td>
        <td>3td>
        <td>4td>
        <td>5td>
        <td> td>
    tr>
    <tr>
        <td>cctd>
        <td>2td>
        <td>3td>
        <td>5td>
        <td>5td>
        <td> td>
    tr>
    <tr>
        <td>dtd>
        <td>1td>
        <td>2td>
        <td>3td>
        <td>4td>
        <td> td>
    tr>
    <tr>
        <td>etd>
        <td>1td>
        <td>2td>
        <td>3td>
        <td>4td>
        <td> td>
    tr>
table><br /><br />
<table width="400" border="1" id="table1">
    <tr>
        <td>atd>
        <td>1td>
        <td>2td>
        <td>3td>
        <td>4td>
        <td>5td>
    tr>
    <tr>
        <td>atd>
        <td>1td>
        <td>2td>
        <td>3td>
        <td>4td>
        <td>6td>
    tr>
    <tr>
        <td>atd>
        <td>2td>
        <td>3td>
        <td>3td>
        <td>4td>
        <td> td>
    tr>
    <tr>
        <td>btd>
        <td>3td>
        <td>4td>
        <td>6td>
        <td>7td>
        <td> td>
    tr>
    <tr>
        <td>btd>
        <td>3td>
        <td>5td>
        <td>6td>
        <td>7td>
        <td> td>
    tr>
    <tr>
        <td>cctd>
        <td>2td>
        <td>3td>
        <td>4td>
        <td>5td>
        <td> td>
    tr>
    <tr>
        <td>cctd>
        <td>2td>
        <td>3td>
        <td>5td>
        <td>5td>
        <td> td>
    tr>
    <tr>
        <td>dtd>
        <td>1td>
        <td>2td>
        <td>3td>
        <td>4td>
        <td> td>
    tr>
    <tr>
        <td>etd>
        <td>1td>
        <td>2td>
        <td>3td>
        <td>4td>
        <td> td>
    tr>
table>
body>
html>