Php Jquery在单独的选择框中获取年份和月份

Php Jquery在单独的选择框中获取年份和月份,php,jquery,Php,Jquery,我在表格中有D.O.B选择框,我想根据所选的年份和月份填充精确的天数 年份: <select name="yy" id="yy" class="box"> <option value="2013">2013</option> . . <option value="1955">1955</option> </select> <select name="mm" id="mm" class=

我在表格中有D.O.B选择框,我想根据所选的年份和月份填充精确的天数

年份:

<select name="yy" id="yy" class="box">
    <option value="2013">2013</option>
    .
    .
    <option value="1955">1955</option>
</select>
<select name="mm" id="mm" class="box">
    <option value="01">01</option>
    .
    .
    <option value="12">12</option>
</select>
在jqueryonchange中,如何将
yy
mm
值传递到
days\u月($month,$year)
如下所示

$('#mm').on('change', function() {
    alert( this.value );
});

我不希望每次更改选定值时都刷新页面。

您可以使用javascript来完成此操作,在这种情况下,无需将ajax与php结合使用:

<script type='text/javascript'>

function days_in_month(month, year){
    // calculate number of days in a month
    return month == 2 ? (year % 4 ? 28 : (year % 100 ? 29 : (year % 400 ? 28 : 29))) : ((month - 1) % 7 % 2 ? 30 : 31);
}

$(document).ready(function() {

 $('#mm').change(function(){

  var mm=$(this).val();//get the month
  var yy=$('#yy').val();//get the day
  $('#dd').val(days_in_month(mm,yy));// i assume that your input for day has id='dd'

 });
});

</script>

功能日(月、年){
//计算一个月的天数
返回月份==2?(第%4-28年:(第%100-29年:(第%400-28:29年)):((第-1个月)%7%2-30:31);
}
$(文档).ready(函数(){
$('#mm')。更改(函数(){
var mm=$(this.val();//获取月份
var yy=$('#yy').val();//获取日期
$('#dd').val(月内天数(mm,yy))//我假设您对天的输入具有id='dd'
});
});

如果不想刷新,您必须发送一个ajax调用,您必须使用ajax来完成此操作。为什么不将php函数更改为javascript函数?如果您仍然需要将变量传输到php函数,则需要javascript中的ajaxany示例函数?@conmen检查我的answer@conmen一旦我的答案中添加了更改,我是否需要使用带有天数选项的
dd
选择框?@conmen喜欢编码:)
<script type='text/javascript'>

function days_in_month(month, year){
    // calculate number of days in a month
    return month == 2 ? (year % 4 ? 28 : (year % 100 ? 29 : (year % 400 ? 28 : 29))) : ((month - 1) % 7 % 2 ? 30 : 31);
}

$(document).ready(function() {

 $('#mm').change(function(){

  var mm=$(this).val();//get the month
  var yy=$('#yy').val();//get the day
  $('#dd').val(days_in_month(mm,yy));// i assume that your input for day has id='dd'

 });
});

</script>