我想用JavaScript动态输入内容以显示名称项中的项代码(我从数据库中获取)。 如果我选择了商品的名称,那么商品的代码将显示在输入字段(code2),并且我有一个像这样的脚本:
$(document).ready(function() {
$("#add_btn").click(function(){
let count = $('tr.records').length+1;
$('#container').append(
'<tr class="records">'
+ '<td><div id="'+count+'">' + count + '</div></td>'
+ '<td> </td>'
+ '<td style="width:100px"><select class="form-control-sm form-control" name="itemname'+count+'" id="item'+count+'" onchange="changeValue2(this.value)" required><option>Chose Item</option><?php include "config.php";$result = mysql_query("select * from code2 order by code_2");$jsArray = "var dtcode = new Array();";while ($row = mysql_fetch_array($result)) { echo '<option value="' . $row['itemname'] . '">' . $row['itemname'] . '</option>';$jsArray .= "dtcode['" . $row['itemname'] . "'] = {code_2:'" . addslashes($row['code_2']) . "'};";}?></select></td>'
+ '<td style="width:50px"><input class="form-control form-control-sm" name="code_2'+count+'" id="code_2" disabled></td>'
+ '<td><a class="remove_item" href="#" >Hapus</a>'
+ '<input id="rows_' + count + '" name="rows[]" value="'+ count +'" type="hidden"></td></tr>'
);
});
$(document).on('click',".remove_item", function (ev) {
$(this).parents(".records").fadeOut();
$(this).parents(".records").remove();
$('tr.records div.count').each(index => {
console.log($(this).text())
});
});
})
该脚本无法在第二行显示代码,请帮帮我?!