您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
三六零分类信息网 > 攀枝花分类信息网,免费分类信息发布

js 省地市级联选择_javascript技巧

2025/9/22 20:53:26发布47次查看
demo1为最简单的一份实现,页面id配置需在js文件中写入,适合简单情况
demo2增加了动态配置,可将配置项传入,适合页面存在多个级联下拉
以下为地市数据json格式,可使用ajax获取或者做成ashx/asmx服务也可直接保存为js文件,可根据你的地市数据调整格式,并修改对应源码
复制代码 代码如下:
var _ds_data=[
{
id:0,
name:\u5317\u4eac,
city:[
{
id:1,
name:\u5317\u4eac\u5e02,
area:[{id:1,name:\u4e1c\u57ce\u533a},{...},{...}...]
},...]
}
为防止乱码,使用了unicode编码,转换代码如下:
复制代码 代码如下:
///
/// 将原始字串转换为unicode,格式为u....\u....
///
public static string stringtounicode(string srctext)
{
string dst = ;
char[] src = srctext.tochararray();
for (int i = 0; i {
byte[] bytes = encoding.unicode.getbytes(src[i].tostring());
string str = @\u + bytes[1].tostring(x2) + bytes[0].tostring(x2);
dst += str;
}
return dst;
}
///
/// 将unicode字串\u....\u....格式字串转换为原始字符串
///
public static string unicodetostring(string srctext)
{
string dst = ;
string src = srctext;
int len = srctext.length / 6;
for (int i = 0; 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
打包下载地址
攀枝花分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product