/* Ajax three-level linkage Date: 2013-2-26 settings parameter description ----- buildingUrl: building drop-down data acquisition URL, josn returns buildingValue: default building drop-down value floorUrl: floor data acquisition URL, josn returns floorValue: default floor value nodata: no data status required: required option clickCallback :Callback function when clicked ----------------------------- */ (function($){ $.fn.building=function(settings){ if($(this).size()<1){return;}; // Default value settings=$. extend({ buildingUrl:"js/city.min.js", floorUrl:"js/city.min.js", buildingValue:null, floorValue:null, nodata:null, required:true, clickCallback:function(){} },settings); var box_obj=this; var building_obj=box_obj.find(".building "); var floor_obj=box_obj.find(".choose_floor"); var floorHidden_obj=box_obj.find(".choose_floor_hidden"); var floorPanel_obj=box_obj.find("#floorNum") ; var select_prehtml=(settings.required) ? "" : ""; var prepareSelectHtml=function(jsonArray){ var temp_html=select_prehtml; $.each(jsonArray,function(index,row){ temp_html =" "; }); return temp_html; }; var prepareFloorPanelHtml=function(jsonArray){ var temp_html='
'; var count=0; $.each(jsonArray,function(index,row){ if(count==0){ temp_html ='
'; return temp_html; }; // Assign the secondary drop-down box function var createFloorPanel=function(){ floor_obj.val('Click to select the floor'); floorHidden_obj.val (''); //floorPanel_obj.empty(); if(building_obj.val()==''){ return; } $.getJSON(settings. floorUrl, { buildingId: building_obj.val(), time: new Date().getTime() }, function(jsonResult){ if(!jsonResult.success){ if(settings.nodata==" none"){ floorPanel_obj.css("display","none"); }else if(settings.nodata=="hidden"){ floorPanel_obj.css("visibility","hidden "); }; return; } // Traverse the assigned secondary drop-down list floorPanel_obj.html(prepareFloorPanelHtml(jsonResult.data)); floorPanel_obj.find( 'td').click(function(){ //hide var text = $(this).html(); var value = $(this).attr("floorId"); var other =$(this).attr("other"); floor_obj.val(text); floorHidden_obj.val(value); floorPanel_obj.css("display"," none"); settings.clickCallback(value,text,other); }); /*$('body').filter('.choose_floor').click(function(){ alert(1) floorPanel_obj.css("display","none"); }); */ });
};
var init=function(){ // Traverse the assignment one-level drop-down list $.getJSON(settings.buildingUrl, {time: new Date().getTime() }, function(jsonResult){ if(!jsonResult.success){ return; } // Traverse the assignment one-level drop-down list building_obj.html(prepareSelectHtml(jsonResult.data)); createFloorPanel() ; // If the values of building and floor are passed in, select it. (setTimeout is set for compatibility with IE6) setTimeout(function(){ if(settings.buildingValue && settings.buildingValue.length>0){ building_obj.val(settings.buildingValue); createFloorPanel(); setTimeout(function(){ if(settings.floorValue!=null){ floor_obj.val(settings.floorValue); }; },1) ; }; },1); }); // Event occurs when level one is selected building_obj.bind("change",function(){ createFloorPanel (); }); floor_obj.click(function(){ //show //alert(floorPanel_obj.html()) //floorPanel_obj.css("height ","100px"); //floorPanel_obj.css("width","100px"); //floorPanel_obj.css('floorNum'); floorPanel_obj.css("display", "block"); }); }; //Initialize the first drop-down box init(); }; })(jQuery);
Background processing request and return json data:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn