如何用js实现如下生成新的td标签,并插入一个数

如何用js实现如下生成新的td标签,并插入一个数,第1张

var table = document.querySelector("table")

var tbody = table.tbodies[0]

var tr = tbody.rows[0]

var td = tr.insertCell(tr.children.length)

td.innerHTML = "abc"

OK

<script type="text/javascript">

var learnnum=0

var learntemp=0

function addlearn(){

var learntb = document.getElementById('learntb')

learnnum += 1

learntemp += 1

var learntr = document.createElement('tr')

learntr.id = "learntr"+learnnum

var learntd1 = document.createElement('td')

learntd1.className = "td3"

learntd1.innerHTML = "起止时间:"

var learntd2 = document.createElement('td')

learntd2.className ="td4"

learntd2.innerHTML = "<input type='text' name='learntime"+ learnnum +"'/>"

var learntd3 = document.createElement('td')

learntd3.className = "td3"

learntd3.innerHTML = "毕业学校:"

var learntd4 = document.createElement('td')

learntd4.className ="td4"

learntd4.innerHTML = "<input type='text' name='endschool"+ learnnum +"'/>"

var learntd5 = document.createElement('td')

learntd5.className = "td3"

learntd5.innerHTML = "所学专业:"

var learntd6 = document.createElement('td')

learntd6.className ="td4"

learntd6.innerHTML = "<input type='text' name='professional"+ learnnum +"'/>"

var learntd7 = document.createElement('td')

learntd7.className = "td3"

learntd7.innerHTML = "教育方式:"

var learntd8 = document.createElement('td')

learntd8.className ="td4"

learntd8.innerHTML = "<input type='text' name='way"+ learnnum +"'/>"

learntr.appendChild(learntd1)

learntr.appendChild(learntd2)

learntr.appendChild(learntd3)

learntr.appendChild(learntd4)

learntr.appendChild(learntd5)

learntr.appendChild(learntd6)

learntr.appendChild(learntd7)

learntr.appendChild(learntd8)

learntb.appendChild(learntr)

// var lt = document.getElementById('learntemp')

// lt.value = learntemp

}

</script>

<body onload="addlearn()">

This is my JSP page. <br>

<table>

<tbody id="learntb">

</tbody>

</table>

</body>

成果库修改       要求主题列表随成果类型改变而改变       网上查询资料后开工 在成果类型下拉框添加change()事件触发Dwr 查询主题集合——动态创建/编辑Table       概要代码如下 JS

复制代码 代码如下: //动态获取主题数据 function getzts(){     parentId = document getElementById("bselect ") value    if(parentId!=""){         dwrMethod getZtList(parentId callback )    }else{         //清空主题Table的数据                           var t=document getElementById("zhutiTable")  //获取Table         var length= t rows length          //获得Table下的行数         if(length!= ){              //如果有行 则清空             for(var i=length i>= i )              {               t deleteRow(i)                 }         }         var r = t insertRow()        var c = r insertCell()        c innerHTML="暂无主题列表"        document getElementById( zhutiTable ) appendChild(t)    } } function callback (provinces){     var t=document getElementById("zhutiTable")     //获取Table     var length= t rows length             //获得Table下的行数     if(length!= ){                      //如果有行 则清空         for(var i=length i>= i )              {                  t deleteRow(i)                     }      }     if(provinces length>){                                   for (var i = i <provinces lengthi++) {             //tr                     if(i% == ){                         var r = t insertRow(t rows length)//创建新的行                      }                     //td              var c = r insertCell()                //创建新的列             c innerHTML = "<input type= checkbox name= zhutiIds value="+provinces[i][ ]+">"+provinces[i][ ]            }     }else{         var r = t insertRow()        var c = r insertCell()        c innerHTML="暂无主题列表"    }     document getElementById( zhutiTable ) appendChild(t)}

复制代码 代码如下: lishixinzhi/Article/program/Java/JSP/201311/19848


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11608806.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存