Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP JAVASCRIPT获得年份差异_Javascript_Jquery - Fatal编程技术网

PHP JAVASCRIPT获得年份差异

PHP JAVASCRIPT获得年份差异,javascript,jquery,Javascript,Jquery,我有源代码php表单,有一个inputtext关于日期(YYYY/mm/dd)我想自动计算输入日期之间的差异,我想在输入完差异日期后使用javascript(jquery)。。。文本框中的年份这是我的代码: date.php <form action="url.php" method="post"> ......... <input type:"text" name="date" id="date"/> ......... <inpu

我有源代码
php
表单,有一个
inputtext关于日期(YYYY/mm/dd)
我想自动计算
输入日期之间的差异,我想在输入完差异日期后使用
javascript(jquery)
。。。文本框中的年份这是我的代码:

date.php

<form action="url.php" method="post">
    .........
    <input type:"text" name="date" id="date"/>
    .........
    <input type:"text" name="dur" id="dur" disabled="disable"/>
</form>

当我在这里运行dur its show NaN的值时,你必须传递输入框中的日期更改事件,你将得到两个日期之间的年差

函数getYearDiff(开始日期、结束日期){ 让yearDiff=endDate.getFullYear()-startDate.getFullYear(); 如果(startDate.getMonth()>endDate.getMonth()){ 年差--; }else if(startDate.getMonth()==endDate.getMonth()){ if(startDate.getDate()>endDate.getDate()){ 年差--; }else if(startDate.getDate()==endDate.getDate()){ if(startDate.getHours()>endDate.getHours()){ 年差--; }else if(startDate.getHours()==endDate.getHours()){ if(startDate.getMinutes()>endDate.getMinutes()){ 年差--; } } } } 返回年份差异; }
警报(getYearDiff(firstDate,secondDate))php标记是不相关的:)请。如果你认为这个问题在别处已经有了答案,请投票结束它。好的,先生,谢谢。
function calc(){
   var now = new Date();
   var month = ("0"+(now.getMonth()+1)).slice(-2);
   var month = ("0"+now.getDate()).slice(-2);
   var year = now.getFullYear();
   var date = month+" / "+day+" / "+year;
   var date_form = $('#date').val();

   $('#dur').val(date - date_form);
}