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>
每次更改结算周期后,过期日期也会从收费日期开始更改。
答案 0 :(得分: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());
});
});