Ajax address three-level linkage drop-down table

Source: Internet
Author: User

<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title><Scriptsrc= "Jquery-2.0.0.js"type= "Text/javascript"> </Script><Scriptsrc= "Address.js"type= "Text/javascript"></Script><Scriptsrc= "Addressdata.js"type= "Text/javascript"></Script><Scripttype= "Text/javascript"src= "Myscript.js"></Script><Script>    //calling plug-ins    $(function() {        $("#address").    Provincecity (); });</Script></Head><Body>Method One<DivID= "Address"></Div>Method Two<Table>    <TR>                    <TDAlign= "Right">Location:</TD>                    <TD><SelectID= "Province">                            <option>Select Province</option>                    </Select> <SelectID= "City">                            <option>Select City</option>                    </Select> <SelectID= "area">                            <option>Select Area</option>                    </Select></TD>                </TR></Table></Body></HTML>
 /**myscript.js * Address drop-down single level three linkage*/  $(function(){      var$province =$ ("#province"); var$city =$ ("#city"); var$area =$ ("#area"); $.each (GP,function(index,data) {$province. Append ("<option value= '" +data+ ">" +data+ "</option>");      }); varIndex1= ""; $province. Change (function(){          //clear the drop-down box for City and District$city [0].options.length=1; $area [0].options.length=1; Index1= This. SelectedIndex;//gets the index of the currently selected province          if(index1!=0) {//When selected as "Please select"              //input data to City drop-down$.each (Gc[index1-1],function(index,data) {$city. Append ("<option value= '" +data+ ">" +data+ "</option>");          });            }                }); varIndex2= ""; $city. Change (function(){          //Empty the drop-down box$area [0].options.length=1; Index2= This. SelectedIndex;//gets the index of the currently selected city$.each (ga[index1-1][index2-1],function(index,data) {$area. Append ("<option value= '" +data+ ">" +data+ "</option>");               });  }); });
/**address.js * jQuery: City Linkage Plugin * @example $ ("#address"). Provincecity (); * @params temporarily not*/$.fn. Provincecity=function(){    varSelf = This; //Define 3 default valuesSelf.data ("Province", ["Please select", "Please select"]); Self.data ("City1", ["select", "Please select"]); Self.data ("City2", ["select", "Please select"]); //Insert 3 empty drop-down boxesSelf.append ("<select></select>"); Self.append ("<select></select>"); Self.append ("<select></select>"); //get 3 drop-down boxes respectively    var$sel 1 = self.find ("select"). EQ (0); var$sel 2 = Self.find ("select"). EQ (1); var$sel 3 = Self.find ("select"). EQ (2); //default provincial drop down    if(Self.data ("Province") {$sel 1.append ("<option value=" "+self.data (" province ") [1]+" ' > "+self.data (" province ") [0]+" </option> "); } $.each (GP,function(index,data) {$sel 1.append ("<option value= '" +data+ ">" +data+ "</option>");    }); //The default Level 1 City dropdown    if(Self.data ("City1") {$sel 2.append ("<option value=" "+self.data (" City1 ") [1]+" ' > "+self.data (" City1 ") [0]+" </option> "); }    //The default Level 2 City dropdown    if(Self.data ("City2") {$sel 3.append ("<option value=" "+self.data (" City2 ") [1]+" ' > "+self.data (" City2 ") [0]+" </option> "); }    //Provincial linkage Control    varIndex1 = "" ; $sel 1.change (function(){        //Empty the other 2 drop-down boxes$sel 2[0].options.length=0; $sel 3[0].options.length=0; Index1= This. SelectedIndex; if(index1==0) {//When selected as "Please select"            if(Self.data ("City1") {$sel 2.append ("<option value=" "+self.data (" City1 ") [1]+" ' > "+self.data (" City1 ") [0]+" </option> "); }            if(Self.data ("City2") {$sel 3.append ("<option value=" "+self.data (" City2 ") [1]+" ' > "+self.data (" City2 ") [0]+" </option> "); }        }Else{$.each (gc[index1-1],function(index,data) {$sel 2.append ("<option value= '" +data+ ">" +data+ "</option>");            }); $.each (Ga[index1-1][0],function(index,data) {$sel 3.append ("<option value= '" +data+ ">" +data+ "</option>");        });    }}). change (); //1-level city linkage control    varIndex2 = "" ; $sel 2.change (function() {$sel 3[0].options.length=0; Index2= This. SelectedIndex; $.each (Ga[index1-1][INDEX2],function(index,data) {$sel 3.append ("<option value= '" +data+ ">" +data+ "</option>");    });    }); returnSelf ;};

Ajax address three-level linkage drop-down table

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.