选择符号

时间:2018-06-19 10:02:29

标签: javascript jquery ajax datepicker jquery-ui-datepicker

我有2个字段,符号和日期,如果在启用了datepicker后选择了符号,没有选择符号,则datepicker被禁用。

<script src="{{asset('js/libs/jquery.js')}}" crossorigin="anonymous"></script>
<link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css">
<link href="{{asset('css/bootstrap-datetimepicker.min.css')}}" rel="stylesheet" media="screen">
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>




<div class="form-group col-sm-10">
                {!! Form::label('symbol', 'Symbals:') !!}
                {!! Form::select('symbol_id', [''=>'Choose market']  , null, ['class'=>'form-control', 'id'=>'symbol'])!!}
            </div>
<div class="form-group col-lg-5">
                {!! Form::label('tradedate', 'Traded date:') !!}
                <div class=" input-append date form_datetime" data-date="{{date('Y-m-d H:i:s')}}" data-date-format="dd MM yyyy - HH:ii p" data-link-field="dtp_input1">
                    <input size="16" type="text" value="" readonly class="form-control">
                    <span class="add-on"><i class="icon-remove"></i></span>
                    <span class="add-on"><i class="icon-th"></i></span>
                </div>
                <input type="hidden" id="dtp_input1" value="" name="tradedate" />
            </div>

这个脚本是使用datepicker,我使用日期,时间和选择月份的形式,datepicker javascript可用如下: 这个javascript使用timepicker,

<script type="text/javascript">
    $('.form_datetime').datetimepicker({
        //language:  'fr',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1
    });
    $('.form_date').datetimepicker({
        language:  'fr',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        minView: 2,
        forceParse: 0
    });
    $('.form_time').datetimepicker({
        language:  'fr',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 1,
        minView: 0,
        maxView: 1,
        forceParse: 0
    });
</script>

1 个答案:

答案 0 :(得分:1)

// use jquery
// event is fired when select change
$('#symbol').on('change', function() {
    // this.value - to retrieve the value of selected option

    // do whatever you want. Give 'id' to your datepicker and you can use 'addClass' to disable datepicker depends on plugin you use

    // for example
    if (this.value == 0) {
        $('#datepicker').attr('disabled',true);
    } else {
        $('#datepicker').attr('disabled',false);
    }
});

更新

我在这里为你创建了jsfiddle。看它。我想你想要那样的东西。 jsfiddle