js动态生成表格

第一步:

<div id="createTable"> </div>

第二步:

function create(){
        var html = "<table width='100%' cellpadding='0' cellspacing='0'>"
        for(var i=0;i<=12;i++){
            html += '<tr>';
            for(var j=0;j<=31;j++){
                if(i==0 && j==0){
                    html +='<td><div class="d1"><span class="s1">'+'日期'+'</span><span class="s2">'+'月份'+'</span></div></td>';
                }
                else if(i==0){
                    html +='<td>'+j+'</td>';
                }
                else if(j==0){
                    html +='<td>'+i+'</td>';
                }else{
                    html +='<td><select id='+i+'><option></option><option value = '+1+'>1</option><option value = '+2+'>2</option></select></td>';
                }
            }
            html += '</tr>';
        }
        html += '</table>';
        $("#createTable").html(html);
    }

结果

js动态生成表格

备注,表头画斜线的找个css就可以,看自己需不需要