【发布时间】:2017-10-13 06:36:10
【问题描述】:
我有 2 个 ID 为 select1 和 otherselect1 的选择框。我在 select1 上触发了一个 onchange 事件以将数据附加到 otherselect1。
现在我通过将 id 增加到 +1 来动态添加多个这些选择框组合。例如:select2 和 otherselect2、select3 和 otherselect3。
问题是我如何编写 onchange 事件,以便如果我更改 select2 它只会影响 otherselect2 的数据,对于 select3 和 otherselect3。
代码:
$('.select_type').on('change', function() {
var channel_type = $(this).val();
return $.ajax({
url: __SITE.baseUrl ,
data: "channel_type=" + channel_type
success: function (data)
{
if (data) {
data = JSON.parse(data);
var total = data.length;
$(this).next('.select_user').html('');
$(this).next('.select_user').append($('<option/>', {value: '', text : 'Choose One'}));
for(var i=0; i < total; i++)
{
$(this).next('.select_user').append($('<option/>', {value: data[i]['id'], text : data[i]['name']}));
}
}
}
});
});
【问题讨论】:
标签: javascript jquery onchange