-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 に答える