這篇文章主要講解了“javascript創(chuàng)建表格,添加刪除操作的方法是什么”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“javascript創(chuàng)建表格,添加刪除操作的方法是什么”吧!
這是用基本的方式,更便捷的方法是,使用es6提供的模板字符串,代碼和效率能提高很多簡(jiǎn)單的樣式:
a <input type="text"/>
b <input type="text"/>
c <input type="text"/><input type="button" value="添加"/><table></table>
js實(shí)現(xiàn)代碼:
var oinput=document.getElementsByTagName("input");var otable=document.getElementsByTagName("table")[0];
oinput[oinput.length-1].onclick=function(){
var otr=document.createElement("tr");
//創(chuàng)建單元格,并且將文本的值加到單元格里
for(var i=0;i<oinput.length-1;i++){
var otd=document.createElement("td");
otd.innerHTML=oinput[i].value;
otr.appendChild(otd);
}
//添加刪除按鈕,并加入到單元格中
var otd = document.createElement("td");
var oSpan = document.createElement("span");
oSpan.innerHTML = "刪除";
otd.appendChild(oSpan);
otr.appendChild(otd);
oSpan.onclick = function(){
//oTable.removeChild(oTr);
otable.removeChild(this.parentNode.parentNode);
}
otable.appendChild(otr);}
進(jìn)度條html排版樣式:
<div class="progressBar">
<p style=""></p></div><div class="progressBar">
<p></p></div><div class="progressBar">
<p></p></div>
js執(zhí)行代碼:
var opp=document.getElementsByTagName("p");function progress(obj,num){
var count=0;
var timer=setInterval(function(){
count++;
obj.style.width=count+"%";
if(count==num){
clearInterval(timer);
}
},20)}progress(opp[0],50);progress(opp[1],60);progress(opp[2],80);
感謝各位的閱讀,以上就是“javascript創(chuàng)建表格,添加刪除操作的方法是什么”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)javascript創(chuàng)建表格,添加刪除操作的方法是什么這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
當(dāng)前文章:javascript創(chuàng)建表格,添加刪除操作的方法是什么-創(chuàng)新互聯(lián)
文章地址:http://aaarwkj.com/article20/ccjpco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、Google、小程序開發(fā)、品牌網(wǎng)站設(shè)計(jì)、服務(wù)器托管、關(guān)鍵詞優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容