[英]repeat element by javascript
I want to repeat these elements: contain a cell and select menu bring data from the database through while 我想重复这些元素:包含一个单元格并选择菜单,将数据库中的数据通过
<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>
in another div: 在另一个div中:
<div id="wrapper">
</div>
Using Javascript code: 使用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>
The innerHTML
property is for setting HTML (string) to the element. innerHTML
属性用于将HTML(字符串)设置为元素。 If you want to add an element object itself, you need to use .appendChild()
如果要添加元素对象本身,则需要使用
.appendChild()
Replace 更换
document.getElementById('wrapper').innerHTML = el;
with 与
document.getElementById('wrapper').appendChild(el);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.