Provincial/Municipal connection selection JS

Source: Internet
Author: User

Author: Truly

 

Source code download

 

Level 3 provincial/municipal joint menu, ie/FF test passed, support multiple coexistence, support event

 

Demo1 is the simplest implementation. The page ID configuration needs to be written in the JS file, which is suitable for simple scenarios.

Dynamic configuration is added for demo2, which can be passed in. It is suitable for multiple cascading drop-down lists on the page.

 

 

The following is the JSON format of local data. You can use ajax to obtain or make it into the ashx/asmx service or directly save it as a JS file,You can adjust the format based on your city data and modify the source code.
VaR _ ds_data = [
{
ID: 0,
Name: "\ u5317 \ u4eac ",
City :[
{
ID: 1,
Name: "\ u5317 \ u4eac \ u5e02 ",
Area: [{ID: 1, name: "\ u4e1c \ u57ce \ u533a" },{...}, {...}...]
},...]
}
Unicode encoding and conversion are used to prevent garbled charactersCodeAs follows:

/// <Summary>
/// Convert the original string to Unicode in the format of \ U ....
/// </Summary>
Public static string stringtounicode (string srctext)
{
String DST = "";
Char [] src = srctext. tochararray ();
For (INT I = 0; I <SRC. length; I ++)
{
Byte [] bytes = encoding. Unicode. getbytes (SRC [I]. tostring ());
String STR = @ "\ U" + bytes [1]. tostring ("X2") + bytes [0]. tostring ("X2 ");
DST + = STR;
}
Return DST;
}

/// <Summary>
/// Convert the Unicode string \ U... to the original string
/// </Summary>
Public static string unicodetostring (string srctext)
{
String DST = "";
String src = srctext;
Int Len = srctext. Length/6;

For (INT I = 0; I <= len-1; I ++)
{
String STR = "";
STR = SRC. substring (0, 6). substring (2 );
Src = SRC. substring (6 );
Byte [] bytes = new byte [2];
Bytes [1] = byte. parse (Int. parse (Str. substring (0, 2), numberstyles. hexnumber). tostring ());
Bytes [0] = byte. parse (Int. parse (Str. substring (2, 2), numberstyles. hexnumber). tostring ());
DST + = encoding. Unicode. getstring (bytes );
}
Return DST;
}

 

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.