我想計算某個日期之間的日期,我使用日期和時間。在鉻工作正常,但在Firefox給我「NaN」,沒有測試它,但我認爲這將是同樣的結果。 jquery日期和時間計算Firefox NaN
<form action="" enctype="multipart/form-data" id="userForm" method="post">
<table border="0">
<tbody>
<tr class="rsform-block rsform-block-paemimodata">
<td>Delivery Date (*)</td>
<td><input type="text" class="datepicker rsform-input-box hasDatepicker" id="paemimodata" name="form[paemimodata]" size="20" value="2013-05-15"></td>
</tr>
<tr class="">
<td>Time (Hours) (*)</td>
<td><select class="rsform-select-box" id="paemimolaikas" name=""><option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
</select>
</td>
</tr>
<tr class="">
<td>Time (minutes)</td>
<td><select class="rsform-select-box" id="paemimolaikasmin" name="">
<option value="05">05</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>
<option value="30">30</option>
<option value="35">35</option>
<option value="40">40</option>
<option value="45">45</option>
<option value="50">50</option>
<option value="55">55</option>
<option value="00">00</option>
</select>
</td>
返回日期() 時間(小時)() 時間(分鐘)
</form>
</xmp>
Java腳本
<pre>
jQuery(function ($) {
function coundays() {
var starter = $('#paemimodata').val();
var starterhour = $('#paemimolaikas').val();
var startermin = $('#paemimolaikasmin').val();
var ender = $('#grazinimodata').val();
var enderhour = $('#grazinimolaikas').val();
var endermin = $('#grazinimolaikasmin').val();
var fullstarter = starter + ' ' + starterhour + ':' + startermin + ':00';
var fullender = ender + ' ' + enderhour + ':' + endermin + ':00';
var start = new Date(fullstarter);
var end = new Date(fullender);
var diff = new Date(end - start);
var days = diff/1000/60/60/24;
alert(days);
};
coundays();
$('#userForm').on('change', function() {
coundays();
});
});
</pre>
的js fidlle
http://jsfiddle.net/dezignas/j2HGw/13/
我在做什麼錯在這裏?
您是否嘗試過使用[parseInt](http://www.w3schools.com/jsref/jsref_parseint.asp)? – 2013-05-07 20:18:53