[英]repeat element by javascript
我想重復這些元素:包含一個單元格並選擇菜單,將數據庫中的數據通過
<div id="orginal">
<td width="99">
<select name= "certificate" id="xx"
onchange="BK.Ajax.Updates('newfile.php?id='+document.getElementById('xx').value,'ajx');" size="1">
<option>.....</option>
<?
$sql_company=mysql_query("select * from company");
while ($row=mysql_fetch_array($sql_company))
{
echo "<option value='$row[id]'> ";
echo $row['name'] ;
echo "</option>";
}
?></select>
</td>
在另一個div中:
<div id="wrapper">
</div>
使用Javascript代碼:
<script language="javascript">
function repeat()
{
var el = document.createElement('div');
var oldHTML = document.getElementById('orginal').innerHTML;
el.innerHTML = oldHTML;
document.getElementById('wrapper').innerHTML = el;
}
</script>
innerHTML
屬性用於將HTML(字符串)設置為元素。 如果要添加元素對象本身,則需要使用.appendChild()
更換
document.getElementById('wrapper').innerHTML = el;
與
document.getElementById('wrapper').appendChild(el);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.