<div class="blogpost-body" id="cnblogs_post_body">
<p>首先访问该链接:http://www.jq22.com/jquery-info12914</p>
<p>看看是否是你要找的三级联动插件,(主要看注释的部分!)</p>
<p>好了,不知道是不是我傻,没有找到初始化数据的方法,本人只能直接格式化一下代码,直接改源码,总之呢,三个地方要改动,看源码:</p>
<p>修改:city-picker.min.js</p>
<div class="cnblogs_code">
<pre class="blockcode"><span style="color:#008080;"> 1</span> <span style="color:#008000;">//</span><span style="color:#008000;"> jshint ignore: start</span>
<span style="color:#008080;"> 2</span> +
<span style="color:#008080;"> 3</span> <span style="color:#0000ff;">function</span><span style="color:#000000;">(e) {
</span><span style="color:#008080;"> 4</span> <span style="color:#008000;">//</span><span style="color:#008000;">开发时,直接把数据库数据设置给rawCitiesData,注意,这里要转json对象,不是json字符串。</span>
<span style="color:#008080;"> 5</span> e.rawCitiesData =<span style="color:#000000;"> [{//全国的数据太长,只能先放一个北京
</span><span style="color:#008080;"> 6</span> name: "北京"<span style="color:#000000;">,
</span><span style="color:#008080;"> 7</span> code: "110000"<span style="color:#000000;">,
</span><span style="color:#008080;"> 8</span> <span style="color:#000000;"> sub: [{
</span><span style="color:#008080;"> 9</span> name: "北京市"<span style="color:#000000;">,
</span><span style="color:#008080;"> 10</span> code: "110000"<span style="color:#000000;">,
</span><span style="color:#008080;"> 11</span> <span style="color:#000000;"> sub: [{
</span><span style="color:#008080;"> 12</span> name: "东城区"<span style="color:#000000;">,
</span><span style="color:#008080;"> 13</span> code: "110101"
<span style="color:#008080;"> 14</span> <span style="color:#000000;"> }]
</span><span style="color:#008080;"> 15</span> <span style="color:#000000;"> }]
</span><span style="color:#008080;"> 16</span> <span style="color:#000000;"> }]
</span><span style="color:#008080;"> 17</span> <span style="color:#000000;">} ($),
</span><span style="color:#008080;"> 18</span> +
<span style="color:#008080;"> 19</span> <span style="color:#0000ff;">function</span><span style="color:#000000;">(e) {
</span><span style="color:#008080;"> 20</span> "use strict"<span style="color:#000000;">;
</span><span style="color:#008080;"> 21</span> <span style="color:#0000ff;">var</span> n, a =<span style="color:#000000;"> e.rawCitiesData,
</span><span style="color:#008080;"> 22</span> c = <span style="color:#0000ff;">function</span><span style="color:#000000;">(e) {
</span><span style="color:#008080;"> 23</span> <span style="color:#0000ff;">for</span> (<span style="color:#0000ff;">var</span> n = [], a = 0; a < e.length; a++<span style="color:#000000;">) {
</span><span style="color:#008080;"> 24</span> <span style="color:#0000ff;">var</span> c =<span style="color:#000000;"> e[a];
</span><span style="color:#008080;"> 25</span> <span style="color:#008000;">//</span><span style="color:#008000;">注意,这里过滤条件,比如:北京是的二级是市辖区,如果不把'市辖区'这个条件去掉,那么,市辖区下的所有数据就没有了。</span>
<span style="color:#008080;"> 26</span> /^请选择|市辖区/.test(c.name) ||<span style="color:#000000;"> n.push(c)
</span><span style="color:#008080;"> 27</span> <span style="color:#000000;"> }
</span><span style="color:#008080;"> 28</span> <span style="color:#0000ff;">return</span> n.length ?<span style="color:#000000;"> n: []
</span><span style="color:#008080;"> 29</span> <span style="color:#000000;"> },
</span><span style="color:#008080;"> 30</span> o = <span style="color:#0000ff;">function</span><span style="color:#000000;">(e) {
</span><span style="color:#008080;"> 31</span> <span style="color:#0000ff;">return</span> e.sub ?<span style="color:#000000;"> c(e.sub) : [{
</span><span style="color:#008080;"> 32</span> name: ""<span style="color:#000000;">,
</span><span style="color:#008080;"> 33</span> <span style="color:#000000;"> code: e.code
</span><span style="color:#008080;"> 34</span> <span style="color:#000000;"> }]
</span><span style="color:#008080;"> 35</span> <span style="color:#000000;"> },
</span><span style="color:#008080;"> 36</span> m = <span style="color:#0000ff;">function</span><span style="color:#000000;">(e) {
</span><span style="color:#008080;"> 37</span> <span style="color:#0000ff;">for</span> (<span style="color:#0000ff;">var</span> n = 0; n < a.length; n++) <span style="color:#0000ff;">if</span> (a[n].code === e || a[n].name === e) <span style="color:#0000ff;">return</span><span style="color:#000000;"> o(a[n]);
</span><span style="color:#008080;"> 38</span> <span style="color:#0000ff;">return</span><span style="color:#000000;"> []
</span><span style="color:#00808 |
|