欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript實(shí)現(xiàn)的動(dòng)態(tài)添加表單元素input,button等(appendChild)

 更新時(shí)間:2007年11月24日 12:22:31   投稿:mdxy-dxy  
這篇文章給大家介紹了javascript實(shí)現(xiàn)的動(dòng)態(tài)添加表單元素input,button等(appendChild)的實(shí)例代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧

寫一個(gè)小系統(tǒng)時(shí),需要?jiǎng)討B(tài)添加表單元素,按自己的實(shí)現(xiàn)方法寫了這篇教程!

我想各位在很多網(wǎng)站上都看到過類似的效果!

1、先用document.createElement方法創(chuàng)建一個(gè)input元素!

var newInput = document.createElement("input"); 

2、設(shè)定相關(guān)屬性,如name,type等

newInput.type=mytype;  
newInput.name="input1"; 

3、用appendChild方法,將元素追加到某個(gè)標(biāo)簽內(nèi)容中!

TemO.appendChild(newInput); 

Javascrip核心代碼:

<script language="javascript"> 
function AddElement(mytype){ 
var mytype,TemO=document.getElementById("add"); 
var newInput = document.createElement("input");  
newInput.type=mytype;  
newInput.name="input1"; 
TemO.appendChild(newInput); 
var newline= document.createElement("br");//創(chuàng)建一個(gè)BR標(biāo)簽是為能夠換行! 
TemO.appendChild(newline); 
} 
</script> 
<html > 
<head> 
<title>動(dòng)態(tài)添加表單元素</title> 
</head> 
<script language="javascript"> 
function AddElement(mytype){ 
var mytype,TemO=document.getElementById("add"); 
var newInput = document.createElement("input"); 
newInput.type=mytype; 
newInput.name="input1"; 
TemO.appendChild(newInput); 
var newline= document.createElement("br"); 
TemO.appendChild(newline); 
} 
</script> 
<body> 
 <form action="" method="get" name="frm"> 
 <div id="add"> 
      <input type="text" name="textfield"><br> 
</div> 
 </form> 
 <input name="" type="button" value="新建文本框" onClick="AddElement('text')" /> 
 <input name="" type="button" value="新建復(fù)選框" onClick="AddElement('checkbox')" /> 
 <input name="" type="button" value="新建單選框" onClick="AddElement('radio')" /> 
 <input name="" type="button" value="新建文件域" onClick="AddElement('file')" /> 
 <input name="" type="button" value="新建密碼框" onClick="AddElement('password')" /> 
 <input name="" type="button" value="新建提交按鈕" onClick="AddElement('submit')" /> 
 <input name="" type="button" value="新建恢復(fù)按鈕" onClick="AddElement('reset')" /> 
</body> 
</html>

以上所述是小編給大家介紹的javascript實(shí)現(xiàn)的動(dòng)態(tài)添加表單元素input,button等(appendChild),希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論