我是Laravel新手,因此这是Interview Schedule
表单的脚本,该脚本基于使用onChange选择的Program
出现:
function changeProgram(input){
var intake_id = $("[name='intake_id']").val();
var campus_input = $(input);
var campus_id = $('[name="program[' + campus_input.data('id') + '][campus_id]"]').val();
$('[name="program[' + campus_input.data('id') + '][program_id]"').empty();
if( campus_id != '' ){
$.ajax({
type: 'GET',
dataType: 'json',
url: '{{ url("campus_program/programs") }}',
data: {
intake_id: intake_id,
campus_id: campus_id
},
success: function (data) {
var select_data = [];
$.each(data, function(i, object) {
select_data.push({id:i, text:object});
});
$('[name="program[' + campus_input.data('id') + '][program_id]"').select2({
data: select_data,
placeholder: "Please Select",
allowClear: true
});
$('[name="program[' + campus_input.data('id') + '][program_id]"]').val('').trigger('change');
@if(!empty($intake_select))
if (intake_id == {{ $intake_select }})
{
@for ($i = 0; $i < $form_setting['total_program']['show']; $i++)
@if (!empty($student_program[$i]->program_id))
<?php $program_id = $student_program[$i]->program_id; ?>
$('[name="program['+{{$i}}+'][program_id]"]').val({{$program_id}}).trigger('change');
@else
$('[name="program['+{{$i}}+'][program_id]"]').val('').trigger('change');
@endif
@endfor
}
@endif
}
});
$('[name="program[' + campus_input.data('id') + '][program_id]"]').attr('onchange','getInterviewSchedule(this)');
} else {
$('[name="program[' + campus_input.data('id') + '][program_id]"').select2({
data: [],
placeholder: "Please Select",
allowClear: true
});
}
}
我希望仅在有数据时显示
Interview Schedule
表单。如果下拉列表中没有表单,如何隐藏表单?提前致谢。
也是刀片的一部分:
<div class="form-group">
<label class="col-lg-2 control-label">{{ msg('lbl_program') }}</label>
<div class="col-lg-6">
{!! Form::dropdown('program['.$i.'][program_id]', $program, @$student_program[$i]->program_id, [
'data-id' => $i,
'class' => 'select2-form program-input'
]) !!}
</div>
</div>
<div class="form-group interview_schedule-div{{$i}} hide">
<label class="col-lg-2 control-label">{{ msg('lbl_interview_schedule') }}</label>
<div class="col-lg-6">
{!! Form::dropdown('program['.$i.'][interview_schedule_id]', ['' => ''], @$student_program[$i]->interview_schedule_id, [
'data-id' => $i,
'class' => 'select2-form program-input'
]) !!}
</div>
</div>
最佳答案
默认情况下,隐藏表单,为您的表单显示提供类和样式:
上课下来尝试一下
$(document).on('change','.dropdown-class-name', funictiion(){
if($(this).val() != "")
{
$('.form-class').show();
}
else
{
$('.form-class').hide();
}
});
谢谢