-1

http://jsfiddle.net/fyv33/505/这个演示

这是我的代码

    <script>
$(function() {
        $( "#datepicker" ).datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'MM d, yy'
        });
        $( "#datepicker2" ).datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'MM d, yy'
        });
    });
</script>

<li><label for="billing_cycle">Billing</label>
<select name="billing_cycle" >
        <option >monthly</option>
        <option >6 months (5% off)</option>
        <option >12 months</option>

<li><label for="charged_datetime">Charge Date</label>
 <input type="text" id="datepicker" value="August 10,2012"></li>
<li><label for="expired_datetime">Expiring Date</label>
  <input type="text" id="datepicker2" value="September 10,2012"></li>

每次我更改计费周期,过期日期也会更改,从收费日期开始。

4

1 回答 1

0
<script>
$(function() {
    $( "#datepicker" ).datepicker({
        changeMonth: true,
        changeYear: true,
        dateFormat: 'MM d, yy',
        altField: "#datepicker2",
        altFormat: 'MM d, yy'
    });
    $( "#datepicker2" ).datepicker({
        changeMonth: true,
        changeYear: true,
        dateFormat: 'MM d, yy'
    });

    var updateExpDate = function(monthToAdd) {
        var now = new Date($('#datepicker').val());
        monthToAdd = parseInt(monthToAdd);
        var a = new Date(now).setMonth(now.getMonth() + monthToAdd);
        var exp_date = new Date(a);
        $('#datepicker2').datepicker('setDate', exp_date);
    };
    $("#datepicker").datepicker({
        changeMonth: true,
        changeYear: true,
        dateFormat: 'MM d, yy'
    });
    $("#datepicker2").datepicker({
        changeMonth: true,
        changeYear: true,
        dateFormat: 'MM d, yy'
    });
    $("#billing_cycle").on('change', function() {
        updateExpDate($(this).val());
    });

    $('#datepicker').on('change', function() {
        updateExpDate($('#billing_cycle').val());
    });
});

http://jsfiddle.net/fyv33/523/

于 2012-08-10T10:54:55.390 回答