How to set selected value in dropdown through javascript
This question already has an answer here:
This doesn't interpret the variable therein:
find('option[value=data.tasks_deliverable_id]')
That string value is a literal string. It's specifically looking for a value called "data.tasks_deliverable_id". To use the data
variable, you need it to be outside the string:
find('option[value=' + data.tasks_deliverable_id + ']')
$.get('loadTaskDetails' + $taskId, {taskId: $taskId}, function(data) {
$.each(data, function(i, data) {
$('#ddl_Deliverables option').removeAttr('selected');
$('#ddl_Deliverables').find('option[value="' + data.tasks_deliverable_id + '"]').attr('selected', 'selected');
});
}, 'json');
链接地址: http://www.djcxy.com/p/83908.html