Create a text box that holds the date
Click the text box to pop up a selection box
referencing jquery files
Referencing bootstrap files
Using modal boxes
Using modal box method settings Click the text box to display the modal box
To manually open the modal box:
$ (' id '). Modal (' show ');
Off: (Automatically closes when you click OK)
$ (' id '). Modal (' hide ')
Populate data, create an external JS file
JS Method:
Load year
function Loadnian ()
{
var date=new date;
var year=date.getfullyear ();
var str = "";
for (Var i=year-5;i<year+6;i++) for loop sets the first five years of the current year to the last five years
{
if (i==year) locates the current year
{
str + = "<option selected= ' selected ' value= '" +i+ ">" +i+ "</option>";
}
Else
{
str + = "<option value=" "+i+" > "+i+" </option> ";
}
}
$ ("#nian"). html (str);
}
Load Month
Function Loadyue ()
{
var date=new date;
var yue=date.getmonth () +1;
var str = "";
for (var i=1;i<13;i++)
{
if (I==yue) locates the current month
{
str + = "<option selected= ' selected ' value= '" +i+ ">" +i+ "</option>";
}
Else
{
str + = "<option value= '" +i+ ">" +i+ "</option>";
}
}
$ ("#yue"). html (str);
}
Load days
function Loadtian ()
{
var date=new date;
var Tian = date.getdate ();
var zs = 31; Total days
var Nian = $ ("#nian"). Val (); Take the current selected year and month
var Yue = $ ("#yue"). Val ();
if (Yue = = 4 | | yue==6 | | yue==9 | | yue==11) Judging if it's 4, 6, 9, November that's 30 days.
{
ZS = 30;
}
else if (yue==2) judge if it is February to continue judging the year
{
if ((nian%4==0 && nian%100!=0) | | nian%400==0) is divisible by four and cannot be divisible by 100 as a leap year
{
ZS = 29;
}
Else
{
ZS = 28;
}
}
var str = "";
for (Var i=1;i<zs+1;i++)
{
if (I==tian) locates the current day
{
str + = "<option selected= ' selected ' value= '" +i+ ">" +i+ "</option>";
}
Else
{
str + = "<option value=" "+i+" > "+i+" </option> ";
}
}
$ ("#tian"). html (str);
}
$ (document). Ready (function (e) {
$ ("#nian"). Change (function () {Changed event year changes reload days
Loadtian ();
})
$ ("#yue"). Change (function () {Month changed reload days
Loadtian ();
})
});
Introduction of external JS file
Display the selected year and month in the text box
Add a click event to the Confirmation button in the modal box
The value of the month and day is spelled into a string to find the text box to take a good value in the text box
Simple jquery Date Selection