1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 在js中使用createElement创建HTML对象和元素_无需整理

在js中使用createElement创建HTML对象和元素_无需整理

时间:2022-08-17 10:11:34

相关推荐

在js中使用createElement创建HTML对象和元素_无需整理

为什么80%的码农都做不了架构师?>>>

1.创建链接<scriptlanguage="javascript">varo=document.body;//创建链接functioncreateA(url,text){vara=document.createElement("a");a.href=url;a.innerHTML=text;a.style.color="red";o.appendChild(a);}createA("/","网页教学网");</script>2.创建DIV<scriptlanguage="javascript">varo=document.body;//创建DIVfunctioncreateDIV(text){vardiv=document.createElement("div");div.innerHTML=text;o.appendChild(div);}createDIV("网页教学网:/");</script>3.创建表单项<scriptlanguage="javascript">varo=document.body;//创建表单项functioncreateInput(sType,sValue){varinput=document.createElement("input");input.type=sType;input.value=sValue;o.appendChild(input);}createInput("button","ooo");</script>4.创建表格<scriptlanguage="javascript">varo=document.body;//创建表格functioncreateTable(w,h,r,c){vartable=document.createElement("table");vartbody=document.createElement("tbody");table.width=w;table.height=h;table.border=1;for(vari=1;i<=r;i++){vartr=document.createElement("tr");for(varj=1;j<=c;j++){vartd=document.createElement("td");td.innerHTML=i+""+j;//td.appendChild(document.createTextNode(i+""+j));td.style.color="#FF0000";tr.appendChild(td);}tbody.appendChild(tr);}table.appendChild(tbody);o.appendChild(table);}createTable(270,270,9,9);</script>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。