JQuery--省市区的选择

 效果:
省市区

代码:
 1 ExpandedBlockStart.gif ContractedBlock.gif function  showArea() dot.gif {
 2InBlock.gif $("#addr").remove();
 3InBlock.gif var iptName=$(this).attr("id");
 4InBlock.gif var iptOffSet=$(this).offset();
 5InBlock.gif var iptLeft=iptOffSet.left-160;
 6InBlock.gif var iptTop=iptOffSet.top+20;
 7InBlock.gif var str="<div id='addr'><span>请选择地点<a id='fh'>返回省份列表</a><a id='gb'>[&nbsp;关闭&nbsp;]</a></span><ul></ul><div style='clear:both;'></div></div>";
 8InBlock.gif areasLen=provinceArr.length;
 9InBlock.gif var str2="";
10ExpandedSubBlockStart.gifContractedSubBlock.gif for(var i=0;i<areasLen;i++)dot.gif{
11InBlock.gif  str2=str2+"<li id='p"+provinceArr[i][0]+"'>"+provinceArr[i][1]+"</li>";
12ExpandedSubBlockEnd.gif }

13InBlock.gif $("body").append(str);
14InBlock.gif $("#addr ul").append(str2);
15ExpandedSubBlockStart.gifContractedSubBlock.gif $("#addr").css(dot.gif{left:iptLeft+"px",top:iptTop+"px"});
16ExpandedSubBlockStart.gifContractedSubBlock.gif $("#addr span a#fh").bind("click",function()dot.gif{
17InBlock.gif  $("#addr ul").empty();
18InBlock.gif  $("#addr ul").append(str2);
19ExpandedSubBlockStart.gifContractedSubBlock.gif  $("#addr ul li").bind("click",dot.gif{iptn:iptName},liBind);
20ExpandedSubBlockEnd.gif }
);
21ExpandedSubBlockStart.gifContractedSubBlock.gif $("#addr span a#gb").bind("click",function()dot.gif{
22InBlock.gif  $("#addr").remove();
23ExpandedSubBlockEnd.gif }
);
24ExpandedSubBlockStart.gifContractedSubBlock.gif $("#addr ul li").bind("click",dot.gif{iptn:iptName},liBind);
25ExpandedBlockEnd.gif}

26 ExpandedBlockStart.gifContractedBlock.gif function  setVal(event) dot.gif {
27InBlock.gif var setipt2=event.data.ipt2;
28InBlock.gif var iptText=$(this).text();
29InBlock.gif var iptVal=$(this).attr("id");
30InBlock.gif $("#"+setipt2+"Val").val(iptVal.substring(1));//截取字符串
31InBlock.gif $("#"+setipt2).val(iptText);
32InBlock.gif $("#addr").css("display","none");
33ExpandedBlockEnd.gif}

34 ExpandedBlockStart.gifContractedBlock.gif function  liBind(event) dot.gif {
35InBlock.gif var setipt=event.data.iptn;
36InBlock.gif var liId=$(this).attr("id");
37InBlock.gif var liText=$(this).text();
38InBlock.gif var pArr=eval(liId);
39InBlock.gif pLen=pArr.length;
40ExpandedSubBlockStart.gifContractedSubBlock.gif if(pLen==0)dot.gif{
41InBlock.gif  $("#"+setipt+"Val").val(liId.substring(1,6));//截取字符串
42InBlock.gif  $("#"+setipt).val(liText);
43InBlock.gif  $("#addr").css("display","none");
44ExpandedSubBlockEnd.gif  }

45ExpandedSubBlockStart.gifContractedSubBlock.gif elsedot.gif{
46InBlock.gif  listr="";
47ExpandedSubBlockStart.gifContractedSubBlock.gif  for(j=0;j<pLen;j++)dot.gif{
48InBlock.gif   listr=listr+"<li id='c"+pArr[j][0]+"'>"+pArr[j][1]+"</li>";
49ExpandedSubBlockEnd.gif   }

50InBlock.gif   $("#addr ul").empty();
51InBlock.gif   $("#addr ul").append(listr);
52ExpandedSubBlockStart.gifContractedSubBlock.gif   $("#addr ul li").bind("click",dot.gif{ipt2:setipt},setVal);
53ExpandedSubBlockEnd.gif  }
 
54ExpandedBlockEnd.gif}

转载于:https://www.cnblogs.com/Ethan0728/archive/2009/02/02/Ethan.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值