Home >Backend Development >PHP Tutorial >Imitation webQQ designed by php+js+mysql-<3>The number of days in the month changes with the month_PHP tutorial

Imitation webQQ designed by php+js+mysql-<3>The number of days in the month changes with the month_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:50:48932browse

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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478248.htmlTechArticle注册时,在填写生日的时候,月份的天数会随着月份的改变而改变,这个小功能在很多的地方都用得到哦! 5月份天数随月份改变 PHP代码 [php] s...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn