简体   繁体   中英

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 id="wrapper">
</div>

Using Javascript code:

<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. If you want to add an element object itself, you need to use .appendChild()

Replace

document.getElementById('wrapper').innerHTML = el;

with

document.getElementById('wrapper').appendChild(el);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM