我使用下面的代码生成带有HTML
输入的行。我在按钮onclick
上调用该函数。
function addsav()
{
html = '<tr id="sav_row' + sav_row + '" class="lerako_group">';
html += '<td class="left">';
html += '<div class="form-group">';
html += '<label class="control-label col-sm-3 label4">From address<span class="label_required">*</span></label>';
html += '<div class="col-sm-6">';
html += '<select class="form-control" value="" name="lerako_honnan[' + sav_row + ']"/></select>';
html += '</div>';
html += '</div>';
html += '<div class="form-group">';
html += '<label class="control-label col-sm-3 label4">To address<span class="label_required">*</span></label>';
html += '<div class="col-sm-6">';
html += '<input required class="form-control" type="text" value="" name="lerako_hova[' + sav_row + ']"/>';
html += '</div>';
html += '</div>';
html += '<div class="form-group">';
html += '<label class="control-label col-sm-3 label4">Utca, házszám <span class="label_required">*</span></label>';
html += '<div class="col-sm-6">';
html += '<input required class="form-control" type="text" value="" name="lerako_utca[' + sav_row + ']"/>';
html += '</div>';
html += '</div>';
html += '<div class="form-group">';
html += '<label class="control-label col-sm-3 label4">Átvevő neve, telefonszáma <span class="label_required">*</span></label>';
html += '<div class="col-sm-6">';
html += '<input required class="form-control" type="text" value="" name="lerako_atvevo[' + sav_row + ']"/>';
html += '</div>';
html += '</div>';
html += '<div class="form-group">';
html += '<label class="control-label col-sm-3 label4">Rendelésszám <span class="label_required">*</span></label>';
html += '<div class="col-sm-6">';
html += '<input required class="form-control" type="text" value="" name="lerako_rendeles_szam[' + sav_row + ']"/>';
html += '</div>';
html += '</div>';
html += '<div class="form-group">';
html += '<label class="control-label col-sm-3 label4">Termékek neve, mennyisége <span class="label_required">*</span><span class="label_help">ENTER-rel elválasztva, külön sorokban.<br> Pl.: Termék neve - Mennyisége</span></label>';
html += '<div class="col-sm-6">';
html += '<textarea rows="4" required class="form-control" name="lerako_termekek[' + sav_row + ']"></textarea>';
html += '</div>';
html += '</div>';
html += '</td>';
html += '<td class="right"><a class="btn btn-sm btn-danger" onclick="$(\'#sav_row' + sav_row + '\').remove();"><span class="glyphicon glyphicon-trash"></span></a></td>';
html += '</tr>';
$('#sav .new-row').before(html);
sav_row++;
}
在forst div中,有一个选择。
在sql表中,我有一个城市列表。我如何将它们放入此选择中?
现在,我只是简单地在体内回显它们,而不是在javascript函数中生成html。
<select name="fuvar_hova" class="form-control chosen-select" id="fuvar_hova">
<?php
$ertek = isset($_POST["fuvar_hova"]) ? $_POST["fuvar_hova"] : 1;
$get_gyartok = mysqli_query($kapcs, "SELECT VarosID, VarosNev FROM Varosok ORDER BY VarosNev ASC");
if(mysqli_num_rows($get_gyartok) > 0 )
{
while($gy = mysqli_fetch_assoc($get_gyartok))
{
$selected = $ertek == $gy['VarosID'] ? ' selected="selected"':'';
echo '<option ' . $selected . ' value="' . $gy['VarosID'] . '">' . $gy['VarosNev'] . '</option>';
}
}
?>
</select>
答案 0 :(得分:0)
在函数
中追加html后添加以下行$('select[name^="lerako_honnan"]').append($('#fuvar_hova').html());
或更改:
html += '<div class="form-group">';
html += '<label class="control-label col-sm-3 label4">From address<span class="label_required">*</span></label>';
html += '<div class="col-sm-6">';
html += '<select class="form-control" value="" name="lerako_honnan[' + sav_row + ']"/>'+$('#fuvar_hova').html()+'</select>';
html += '</div>';
html += '</div>';