$(function() { //给图标的加减号添加展开收缩行为 $('img[ds_type="flex"]').click(function(){ var status = $(this).attr("status"); //状态是加号的事件 if(status == 'open') { var pr = $(this).parent('td').parent('tr'); var id = $(this).attr("fieldid"); var obj = $(this); $(this).attr('status','none'); $.get(AJAX_URL_REGION, {id: id}, function(data){ if(data) { var str = ""; var res = eval('('+data+')'); for(var i = 0; i < res.length; i++) { var tmp_vertline = ""; str += ""; str += ""; //给每一个异步取出的数据添加伸缩图标后者无状态图标 if(res[i].switchs == 1) { str += ""; } else { str += ""; } str += ""; //排序 str += " "+res[i].area_sort+""; //名称 str += ""; for (var tmp_i = 1; tmp_i < (res[i].area_deep - 1); tmp_i++) { str += tmp_vertline; } if (res[i].switchs == 1) { str += " "; } else { str += " "; } str += " "+res[i].area_name+""; str += ""; //大区名称 str += ""; for (var tmp_i = 1; tmp_i < (res[i].deep - 1); tmp_i++) { str += tmp_vertline; } if(res[i].area_region == null){ res[i].area_region= ' '; } str += " " + res[i].area_region + ""; str += ""; str += "编辑"; str += "删除"; str += "添加子分类"; str += "" } //将组成的字符串添加到点击对象后面 pr.after(str); obj.attr('status', 'close'); obj.attr('src', obj.attr('src').replace("tv-expandable", "tv-collapsable")); $('img[ds_type="flex"]').unbind('click'); $('span[ds_type="inline_edit"]').unbind('click'); //重现初始化页面 $.getScript(ADMINSITEROOT + "/js/jquery.edit.js"); $.getScript(ADMINSITEROOT + "/js/region_tree.js"); } }); } //状态是减号的事件 if(status == "close") { $(".row"+$(this).attr('fieldid')).remove(); $(this).attr('src',$(this).attr('src').replace("tv-collapsable","tv-expandable")); $(this).attr('status','open'); } }); });