Home > Article > Backend Development > Imitation webQQ designed by php+js+mysql-<3>The number of days in the month changes with the month_PHP tutorial
When registering, when filling in the birthday, the number of days in the month will change with the change of the month. This small function can be used in many places!
<5>The number of days in the month changes with the month
PHP code
[php]
Month
Day
Month
日
Js code
[javascript]
function monthDays(month)
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
if(month==2)
{
document.getElementById("day").length=0; //先把月份天数的select的option清空
for(i=1;i<=29;i++)
{
document.getElementById("day").options.add(new Option(i,i));
}
}
else if(month==4||month==6||month==9||month==11)
{
document.getElementById("day").length=0;
for(i=1;i<=30;i++)
{
document.getElementById("day").options.add(new Option(i,i));
}
}
else
{
document.getElementById("day").length=0;
for(i=1;i<=31;i++)
{
document.getElementById("day").options.add(new Option(i,i));
}
}
}
}
xmlhttp.open("GET","index.php",true);
xmlhttp.send();
}
function monthDays(month)
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
if(month==2)
{
document.getElementById("day").length=0; //先把月份天数的select的option清空
for(i=1;i<=29;i++)
{
document.getElementById("day").options.add(new Option(i,i));
}
}
else if(month==4||month==6||month==9||month==11)
{
document.getElementById("day").length=0;
for(i=1;i<=30;i++)
{
document.getElementById("day").options.add(new Option(i,i));
}
}
else
{
document.getElementById("day").length=0;
for(i=1;i<=31;i++)
{
document.getElementById("day").options.add(new Option(i,i));
}
}
}
}
xmlhttp.open("GET","index.php",true);
xmlhttp.send();
}
这种效果还是用到Ajax的局部刷新技术,欢迎大家交流学习。(未完待续)
摘自 wyzhangchengjin123