1. TitleEnter a birthday value in the text box and click the button to display the corresponding zodiac sign for this birthday. Define a function that receives a birthday value (a 4-digit string consisting of month and day, such as "0210", "1225", etc.) and indicates the zodiac sign based on the birthday value. 2. Code<!doctype html> <html> <head> <meta charset="utf-8"> <title>Zodiac Query</title> </head> <body> <p align="center"> Please enter a birthday value (eg: 0123): <input type="text" id="t1"> <input type="button" value="Show constellations" onclick="show()"/> </p> <script> function show(){ var c1=document.getElementById("t1").value; //Get the value in the text box //alert(c1); var month=c1.substring(0,2); var day = parseInt(c1.substring(2)); switch(month){ case "01": if(day>19){alert("Aquarius")} else alert("Capricorn"); break; case "02": if(day>18){alert("Pisces")} else alert("Aquarius"); break; case "03": if(day>20){alert("Aries")} else alert("Pisces"); break; case "04": if(day>19){alert("Taurus")} else alert("Aries"); break; case "05": if(day>20){alert("Gemini")} else alert("Taurus"); break; case "06": if(day>21){alert("Cancer")} else alert("Gemini"); break; case "07": if(day>22){alert("Leo")} else alert("Cancer"); break; case "08": if(day>22){alert("Virgo")} else alert("Leo"); break; case "09": if(day>22){alert("Libra")} else alert("Virgo"); break; case "10": if(day>23){alert("Scorpio")} else alert("Libra"); break; case "11": if(day>20){alert("Sagittarius")} else alert("Scorpio"); break; case "12": if(day>21){alert("Capricorn")} else alert("Sagittarius"); break; } } </script> </body> </html> 3. ResultsIV. Conclusion1. First of all, we need to understand the corresponding relationship between constellations and dates: 2. substring(start,end) will return a string containing the substring from start to the end (excluding end); The parseInt() function parses a string and returns an integer. This concludes this article about implementing the constellation query function with JavaScript and attached detailed code. For more relevant js constellation query content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: CSS uses the placeholder-shown pseudo-class to achieve the floating text effect of the input box
>>: Detailed explanation of how to configure openGauss database in docker
I followed the tutorial on W3school. I think the t...
Table of contents Introduction effect principle f...
This article describes the MySQL slow query opera...
Let’s build the data table first. use test; creat...
This article shares the specific code of jQuery t...
This article shares the specific code for using j...
1. First, let's review the relevant knowledge...
Detailed explanation of replace into example in m...
Joint Index The definition of the joint index in ...
Table of contents Node connects to Mysql Install ...
Background: I wonder if you have noticed that if ...
There are too many articles about xhtml+css websi...
As shown below: LOCATE(substr,str) Returns the fi...
The reason why Docker is so popular nowadays is m...
To back up multiple databases, you can use the fo...