我有一个包含天数差异的文本字段。我需要用它来计算我页面上的一些东西。但是,由于某种原因,undefined
当我执行console.log()
. 有任何想法吗?
<script>
$(document).on('change', '#unitselector', function()
{
var unit = $('select option:selected').text();
var rate = $(this).val();
var tax = $('select option:selected').attr('label');
var depart=$('#departdate').val();
var arrival = $('#arrivaldate').val();
var dataString = {unit:unit, depart:depart, arrival:arrival};
console.log(dataString);
//console.log($('.extracharges').serialize());
$.ajax({
type: "POST",
url: "classes/unit_info.php",
data: dataString,
cache: false,
success: function(html)
{
$('.unitinfolist').html(html);
}
});
var days = $('#days').attr('name');
var days2 = $('#days').attr('value');
console.log('days: '+days);
console.log('days: '+ days2 );
$('.rentalcharges').find('#rent').val(rate*days);
});
</script>
和 PHP
$arrive = $_POST['arrival'];
$leave = $_POST['depart'];
$a = date_create($arrive);
$d = date_create($leave);
$diff = date_diff($d,$a);
echo '<input type="text" id="days" value="'.$diff->d.'" name="'.$diff->d.'" />';