ajax获取数据并组装select

技术探讨  2018-01-19 10:33   9237 select ajax
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
    /**
    * 搜索联动
    
    * @param  {[type]} tag     标签
    * @param  {[type]} url     ajax 请求地址
    * @param  {[type]} param   参数
    * @param  {[type]} key     key
    * @param  {[type]} default 默认值
    * @return {[type]}         
    */
    function appendHtmls(tag,url,param,option,select)
    {
         var option  = arguments[3] ? arguments[3] : {id: 'id', name: 'name'};
         var select  = arguments[4] ? arguments[4] : 0;
         $.post(url, param, function (data)
         {
             var html = "<option>===请选择===</option>";
             if(data.status > 0 || data.code > 0)
             {
                 var items = data.data;
                 for (key in items)
                 {
                      if (select !== 0 && items[key][option.id] == select)
                      {
                      html += "<option>"
                            + items[key][option.name] + "</option>"
                      else {
                      html += "<option>" + items[key][option.name] + "</option>";
                      }  
                 }
                 $("#" + tag).html(html);
             else {
                 return false;
             }
         })
     }


注:转载请注明出处为http://www.xtaike.com/article/45.html。

沙豆网 站长

追求卓越,奋斗不息!

169
文章
10495
点赞

更多文章