1 回答
TA贡献1852条经验 获得超7个赞
您可以使用rowID仅更改特定的行选择 $("#" + rowID).find('.tbAnswerddl')。并使用相同的选择附加选项。
演示代码(我已删除此演示中不需要的 ajax 代码):
//dummy data
var result = [{
"AnswerName": "abc",
"AnswerID": "123"
}, {
"AnswerName": "abcd",
"AnswerID": "123a"
}];
$('.tbTestddl').change(function() {
var TestID = $('option:selected', this).val();//value of select-box
var rowID = $(this).closest('tr').attr('id');
console.log("val -"+TestID)
console.log("rowid -"+rowID)
GetAnswer(TestID, rowID);
});
function GetAnswer(TestID, rowID) {
//finding slect under the row given
var clearddl = $("#" + rowID).find('.tbAnswerddl');
clearddl.empty();
$.each(result, function() {
var option = document.createElement("option");
option.text = this.AnswerName;
option.value = this.AnswerID;
clearddl.append(option); //append to that row
});
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr id=102>
<td>
<select name="tbTest" id="tbTest" class="tbTestddl" style="max-width:200px">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
</select>
</td>
<td>
<select name="tbAnswer" id="tbAnswer" class="tbAnswerddl" style="max-width:200px">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
</select>
</td>
</tr>
<tr id=100>
<td>
<select name="tbTest" id="tbTest" class="tbTestddl" style="max-width:200px">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
</select>
</td>
<td>
<select name="tbAnswer" id="tbAnswer" class="tbAnswerddl" style="max-width:200px">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
</select>
</td>
</tr>
</table>
添加回答
举报