我已經使用類型(選擇)、名稱(文本)、單位(選擇)創建了動態行,我正在為更改類型的選擇編寫代碼。但是,當我從類型字段中更改值時,它已將值加載到當前行名稱字段中,并將選項動態加載到當前單元選擇字段中,將值加載到活動行中工作正常,但將選項加載到選擇單元中則不行。我的代碼如下$(document).on('change', '.raw', function () { // var r = this.val(); if ($(this).val() != 0) { var t = $(this).parents('tr').find(".raw :selected").text(); $(this).parents('tr').find(".name").val(t);我需要幫助的地方如下$(this).parents('tr').find(".amount").html(data); -> here i need help// $(".amount").html(data); ->this working fine but change all the select value提前致謝。這是我的表的完整編碼<table id="addingtable" class="table table-bordered"><tr> <th>Raw Master</th> <th>Name</th> <th>Display</th> <th>Value</th> <th>Unit</th> <th>Delete</th></tr><tr> <td><select name='rawmaster[]' class = 'form-control raw' required><option>Select</option><?php echo rawmaster_item($conn,$type); ?><option value="0">None</option></select></td> <td><input type='text' name='name[]' placeholder="Name" class = 'form-control name' required /></td> <td><select name='des[]' class = 'form-control' required><option>Select</option><option Value = 'y'>Yes</option><option Value = 'n'>No</option></select></td> <td><input type='text' name='value[]' placeholder="Value" class = 'form-control' required /></td> <td><select name='amount[]' class = 'form-control amount' required><option>Select</option><?php echo $output2; ?></select></td> <td><button type='button' class='btn btn-icon btn-danger remove'><i class='feather icon-trash-2'></i></button></td></tr>
1 回答

ABOUTYOU
TA貢獻1812條經驗 獲得超5個贊
我可能錯了,但我認為您需要在 ajax 請求上設置上下文,否則this將引用不同的上下文(回調),添加context:this如下:
$.ajax({
url:"plandetails_getunit.php",
method:"POST",
data:"id="+r,
context:this,
success:function(data)
{
- 1 回答
- 0 關注
- 128 瀏覽
添加回答
舉報
0/150
提交
取消