The _javascript skill of the Cascade selection in JS Provincial city

Source: Internet
Author: User
Demo1 for the simplest implementation, page ID configuration needs to be written in the JS file, suitable for simple situations
Demo2 added dynamic configuration, you can pass the configuration entry, suitable for the page exists multiple cascading dropdown
The following is the city data JSON format, you can use Ajax to obtain or make ashx/asmx services can also be directly saved as a JS file, according to your city data adjustment format, and modify the corresponding source code
Copy Code code as follows:

var _ds_data=[
{
id:0,
Name: "\u5317\u4eac",
city:[
{
Id:1,
Name: "\u5317\u4eac\u5e02",
Area:[{id:1,name: "\u4e1c\u57ce\u533a"},{...},{...} ...]
},...]
}

To prevent garbled code, the Unicode encoding is used and the conversion codes are as follows:
Copy Code code as follows:

<summary>
Converts the original string to Unicode, in the form of \u....\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>
\u....\u Unicode string .... format string converted to original
</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 Download Address

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.