Js provincial/municipal connection Selection

Source: Internet
Author: User

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 prefecture-level data json format. 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 prefecture-level data and modify the source code.
Copy codeThe Code is as follows:
Var _ ds_data = [
{
Id: 0,
Name: "\ u5317 \ u4EAC ",
City :[
{
Id: 1,
Name: "\ u5317 \ u4EAC \ u5E02 ",
Area: [{id: 1, name: "\ u4E1C \ u57CE \ u533A" },{...}, {...}...]
},...]
}

Unicode encoding is used to prevent garbled characters. The conversion code is as follows:
Copy codeThe Code is as 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;
}

Http://xiazai.jb51.net/201002/yuanma/cityselector.rar
Package

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.