3

大家好,

     <script type="text/javascript">
          function duedatecal(){
            var invoicedate = $(".invoicedate").val();
             var paymentterms = $(".paymentterms").html();

          }
        </script>
        <apex:form>
        Date:
         <Apex:inputtext value="{!dateIn}" id="time" styleclass="invoicedate" onblur="duedatecal();"/> //say suppose date is 06/03/2013
        Payment Days:
           <apex:outputtext value="{!payment.Net__c}" styleclass="paymentterms"  /> //say suppose will get 10 days here
        Due date:
           <apex:outputtext value="{!duedate}" styleclass="duedate"/> // output shld be 16/03/2013
        </apex:form>

每当我更改 inputtext(of Date) 时,应通过添加 Date+payment Days.Help 相应地显示到期日。

4

3 回答 3

1

为此,您可以:

function duedatecal(){
    var invoicedate = new Date($(".invoicedate").val());
    var paymentterms = $(".paymentterms").html().val();
    var dueDate = new Date();
    dueDate.setDate(invoicedate.getDate()+paymentterms);
    return dueDate;
}
于 2013-06-03T12:44:48.573 回答
1

试试这个:

function duedatecal(){
    var dmy = $(".invoicedate").val().split("/");        
    var invoicedate = new Date(
                   parseInt(dmy[2], 10),
                   parseInt(dmy[0], 10) - 1,
                   parseInt(dmy[1], 10)
                 );

    var paymentterms = $(".paymentterms").text();
    var dueDate = new Date();
    dueDate.setDate(invoicedate.getDate()+parseInt(paymentterms));
    var duedates = dueDate.getDate()+"/"+(dueDate.getMonth()+1)+"/"+dueDate.getFullYear();

    $(".duedate").html(duedates);
}
于 2013-06-03T13:37:33.823 回答
1

您可能需要考虑使用moment.js。它使在 JavaScript 中处理日期和时间变得更加容易。

function duedatecal(){

    // parse the input date using a format string
    var invDate = moment($(".invoicedate").val(), 'DD/MM/YYYY');

    // get an integer for the days of payment terms
    var terms = parseInt($(".paymentterms").text());

    // use moment.add with the days parameter
    var dueDate = invDate.add('days', terms);

    // output the due date, specifying a format string
    $(".duedate").text(dueDate.format('DD/MM/YYYY'));
}

这假设您正在对解析输入和格式化输出的格式进行硬编码。有关其他选项,请参阅moment.js 文档

于 2013-06-04T06:19:10.023 回答