JavaScript makes a drop-down list of provincial and municipal cascading

Source: Internet
Author: User




The Object.options.add (new option Label,value) method adds an option object to the collection;
The Object.options.remove (index) method removes the specified item from the options collection;
Object.options (index) or Options.item (index) can get the specified item of the options collection by index;

The select tag also has a property of SelectedIndex, which may get the currently selected option index: Object.selectedindex

1. Clear the Options collection function Optionsclear (object) {var length = Object.options.length;for (var i=length-1;i>=0;i--) { E.options.remove (i);}} 2. Add a new Optionfunction AddOption (object) {Object.add (new Option (Label,value));// Use the last item in the options collection to get focus Object.selectedindex = object.lentht-1;} 3. Delete an item specified in the Options collection Optionfunction removeoption (index) {if (index >= 0) {object.remove (index);// Use the last item in the options collection to get focus Object.selectedindex = Object.lentht-1;}} 4. Gets the real value of the currently selected option Valuefunction Getcurrentoptionvalue (index) {if (index >= 0) return Object (index). value; 5. Gets the display value of the currently selected option Labelfunction Getcurrentoptionlabel (index) {if (index >= 0) return Object (index). text; The following is the date linkage drop-down box: function YYYYMMDD () {//sets the set of months Monhead = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];//all contents of the purge year drop-down box, most notably The space var yobj = document.form1.yearoptionsClear (yobj);//give the under decade frame the content yObj.options.add ("select", 0)); for (var i = 1950; I <= new Date (). getFullYear (); i++)//On a 1950-year basis, to the end of this year Document.form1.year.options.add (new Option (I, I);//Clears all contents of the Month drop-down box, most notably the space var mobj = document.form1.month;optionsclear (mobj);// Re-assign the month drop-down box document.form1.month.options.add (New option ("select", 0)); for (var i = 1; i <; i++) Document.form1.month.options.add (New Option (i,i));//assigns the year's initial value Document.form1.year.value = Document.getelementsbyname ("YYYY") [0].value;//assigns the month's initial value Document.form1.month.value = Document.getelementsbyname ("MM") [0].value;//date dropdown box var n = monhead[ Document.form1.month.value-1];if (Document.form1.month.value ==2 && ispinyear (yyyyvalue)) N++;writeday (n); /assignment of the initial value of the date Document.form1.date.value = Document.getelementsbyname ("DD") [0].value;} Changes in the date of the year (mainly to judge the leap common year) function Yyyydd (str) {var mmvalue = document.form1.month.options[ Document.form1.month.selectedindex].value;if (Mmvalue = = "") {var e = document.form1.date;optionsclear (e); return;} var n = monhead[mmvalue-1];if (Mmvalue = = 2 && ispinyear (str)) N++;writeday (n)}//Month Change Date linkage function MMDD (str) {V Ar yyyyvalue = Document.form1.year.options[document.form1.year.selectedindeX].value;if (Yyyyvalue = = "") {var e = document.form1.date;optionsclear (e); return;} var n = monhead[str-1];if (str = = 2 && ispinyear (yyyyvalue)) N++;writeday (n)}//the drop-down box function Writeday (n) {v) according to the conditional write date Ar e = document.form1.date;optionsclear (e), for (Var I=1; i< (n+1); i++) E.options.add (new Option (I,i));} Determine if leap common year function ispinyear (year) {return (0 = = year%4 && (year0!=0 | | [email protected] = = 0);} Clears all contents of the drop-down box function Optionsclear (e) {var length = Object.options.length;for (var i=length-1;i>=0;i--) { E.options.remove (i);}}
and send some perks.
1 Check if checked if (Objselect.selectedindex >-1) {//description checked} else {//description not checked}//2 Delete selected item OBJSELECT.OPTIONS[OBJSELECT.SELECTE Dindex] = null;//3 add objselect.options[objselect.length] = new option ("Hello", "Hello");//4 modify the item in the selection objselect.option S[objselect.selectedindex] = new option ("Hi", "Hello");//5 gets the text of the selected item Objselect.options[objselect.selectedindex].text ;//6 gets the value of the selected item Objselect.options[objselect.selectedindex].value;


JavaScript makes a drop-down list of provincial and municipal cascading

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.