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;
}