Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/453.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript启用调度程序_Javascript_Html_Schedule - Fatal编程技术网

javascript启用调度程序

javascript启用调度程序,javascript,html,schedule,Javascript,Html,Schedule,我都, 我有这个密码 <select id = 'jack'> <option id = 'test1' >test1</option> <option id = 'test2' >test2</option> </select> <input id="calendar" type="text" disabled="disabled"/> 当我从菜单test1中选择时,我会确保计划处于活动状态,而如果我选择t

我都, 我有这个密码

<select id = 'jack'>
<option id = 'test1' >test1</option>
<option id = 'test2' >test2</option>
</select>

<input id="calendar" type="text" disabled="disabled"/>

当我从菜单test1中选择时,我会确保计划处于活动状态,而如果我选择test2,我希望保持禁用状态。如果您想在选择test1时激活日历,请尝试以下操作:

$(document).ready(function(){
  $('#jack').on('change', function (e) {
    if($('#jack').val()=="test1"){
      // enable the calendar
      $('#calendar').datepicker({
        format:"mm-dd-yyyy",
        autoclose: true
      });
    }else{
       $('#calendar').datepicker('remove');
    }
  });
});

如果我理解你的问题,你正在寻找这个

var calendar = $("#calendar").datepicker("option", "disabled", true);

$("#jack").on('change', function () {
    if($(this).val() == 'test1') {
        calendar.datepicker( "option", "disabled", false);
    } else {
        calendar.datepicker( "option", "disabled", true);
    }
});

您可以这样做:

$('#jack').on('change', function(e){
    var val = $(this).val();
    $('#calendar').attr('disabled', val == 'test2');
});
我认为,jQuery的“改变”才是前进的方向。然后你就有了一条单行线:

$('#jack').change(function() {
    $('#calendar').attr('disabled', $(this).val() == 'test2');
});
在此显示所需行为的小提琴:

注意:我建议在默认情况下删除“disabled”,因为首先会选择test1


编辑:这会禁用HTML元素本身,但插件会公开一个要禁用的API(请参见其他答案),因此这不是唯一的方法。

如果用户从“test1”更改为“test2”,则日期选择器仍将启用。我知道,当选择test1时,他希望激活日期选择器。我更新了代码,因此在选择其他值时,日期选择器将被删除(禁用)
$('#jack').change(function() {
    $('#calendar').attr('disabled', $(this).val() == 'test2');
});