我想获得文本区域和下拉列表leave_id
的当前值。我从第二个下拉列表中获取申请休假id的当前值。如何获取第一个下拉列表和文本区域的当前值?
$(document).ready(function() {
$('.status').change(function() {
// alert($('.leave_comments').val());
// alert($(this).prev('.leave_type').prop('id'));
var leave_type = $('.leave_comments').val();
var leave_comments = $(this).prev('.leave_type').prop('id');
var leave_id = $(this).prop('id');
var status = $(this).val();
console.log(1);
$.ajax({
url: '<?php echo base_url() ?>leave/status',
data: {
status: status,
leave_id: leave_id
},
dataType: 'html', // return tyoe
success: function(response) { // success response
//$(response).appendTo('#success');
$('#success').html('<div class="alert alert-success alert-dismissible" role="alert"><button type="button" class="close" n
data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>' + response + '</div>');
}
});
});
});
<tbody>
<?php $count=1 ?>
<?php foreach ($leave as $leave): ?>
<tr class="gradeX">
<td>
<?php echo $count++ ?>
</td>
<td id="name">
<?php echo $leave->first_name . ' ' . $leave->last_name ?>
</td>
<td>
<?php echo $leave->leave_applied_date ?>
</td>
<td>
<?php echo $leave->name ?>
</td>
<td>
<?php echo $leave->subject ?>
</td>
<td>
<?php echo date( 'd/m/Y', strtotime($leave->leave_from_date)) . ' - ' . date('d/m/Y', strtotime($leave->leave_to_date)) ?>
</td>
<td>
<?php echo $leave->reason ?>
</td>
<td>
<?php if($leave->leave_comments == null) { ?>
<textarea class="form-control leave_comments" rows="5" placeholder="Type your answer..." required="required"></textarea>
<?php } else { ?>
<?php echo $leave->leave_comments ?>
<?php } ?>
</td>
<td>
<select name="leave_id" class="form-control input-md mb-md leave_type" id="<?php echo $leave->applied_leave_id ?>">
<option value="">Select leave type</option>
<?php foreach($leave_types as $type): ?>
<option value="<?php echo $type->leave_id ?>">
<?php echo $type->name ?></option>
<?php endforeach; ?>
</select>
</td>
<!-- <td><a data-toggle="modal" data-target="#modal_edit" onclick="modal_edit('<?php echo base_url() . 'leave/leave_reason/' . $leave->leave_id . '/' . $leave->employee_id ?>')" data-toggle="tooltip" data-placement="bottom" title="Edit" class="btn-sm btn-warning" href=""><i class="fa fa-pencil"></i></a></td>-->
<td>
<select id="<?php echo $leave->applied_leave_id ?>" class="status" data-plugin-selectTwo class="form-control populate placeholder">
<option value="">
<?php echo $leave->status ? $leave->status : 'Pending' ?>
</option>
<option value="Granted">Granted</option>
<option value="Rejected">Rejected</option>
</select>
</td>
</tr>
<?php endforeach; ?>
</tbody>
尝试以下
var textarea = $(this).closest('.gradeX').find('.leave_comments').val();
var first_select =$(this).closest('.gradeX').find('input[name="leave_id"]').val();