我想通过php中的选择框启用datepicker

时间:2015-02-24 07:42:56

标签: jquery html

<html>
<head>
<link rel="stylesheet" href="../css/ved_emp_main_details_calender_css.css">
<script src="../script/calender_script/ved_emp_main_details_date_script.js"></script>
<script src="../script/calender_script/ved_emp_compoff_date_jquery.js"></script>
<script>
$(function() 
{
    $( "#datepicker" ).datepicker({dateFormat: 'yy-mm-dd',changeMonth: true,
        changeYear: true,yearRange: '1920:2040'});
});



<td>
    <div class="label" nowrap><label><?php echo COLCTED;?></label></div> 
</td>
<td>
    <div class="form-fields">
    <div class="input">
    <select name="iCollected">
        <option  selected value="-1"><?php echo CHOOSE;?></option>
        <option value="1"><?php echo YES;?></option>
        <option value="0"><?php echo NO;?></option>
    </select> 
    </div>
    </div>
</td>

我想在选择框中选择是时传递日期选择器功能。我只想在选择yes时启用日期选择器,否则应禁用日期选择器

1 个答案:

答案 0 :(得分:0)

试试这个: -

$(function() 
{
    $( "#datepicker" ).datepicker({dateFormat: 'yy-mm-dd',changeMonth: true,
        changeYear: true,yearRange: '1920:2040'});

    $('select[name="iCollected"]').change(function(){
       if($(this).val() == "1")
       {
          $( "#datepicker" ).datepicker('enable');;
       }
       else
       {
          $( "#datepicker" ).datepicker('disable');
       }
    }).trigger('change'); //trigger change event on page load.
});

Fiddle