In order to and 10 years ago in the old project technically and logically completely, can be modular JS way and the old project to connect;
//The relevant JS of the competition vehicle system//JS ModulevarJingpinmain = { //Number of drop-down boxesSelectCount:1, //Related Usage APIURL: {//Get all Brandsgetcarbrandurl:function () {return "/newpost/getcarbrand/"; }, //brand get the car line URLgetcarsericesurl:function () {return "/newpost/getcarseries/"; } }, //Initialization of modulesInitmain: {init:function () {varBrandsel = $ ('#tr_jingpin'). Find ('. Brandsel'); varSeriessel = $ ('#tr_jingpin'). Find ('. Seriessel'); Jingpinmain.getallbrand (Brandsel); } }, //Get the brandgetallbrand:function (Brandsel) {$.ajax ({type:"Get", URL:JINGPINMAIN.URL.GETCARBRANDURL (), data: {brandId:jingpinMain.brandId}, dat Atype:"JSON", Success:function (data) {if(Data.length >0) { for(vari =0; i < data.length; i++) {brandsel.append ('<option value= "'+ Data[i]. ItemId +'">'+ Data[i]. ItemName +'</option>'); }}, Error:function (XMLHttpRequest, Textstatus, Errorthrown) {Ale RT ('Err'); } }); }, //get branded Car seriesgetallseries:function (Brandid, obj) {$.ajax ({type:"Get", URL:JINGPINMAIN.URL.GETCARSERICESURL (), data: {Id:brandid}, DataType:"JSON", Success:function (data) {if(Data.length >0) { varbb = $ (obj). Next ('. Seriessel'); for(vari =0; i < data.length; i++) {bb.append ('<option value= "'+ Data[i]. ItemId +'">'+ Data[i]. ItemName +'</option>'); } bb.removeattr ("Disabled"); }}, Error:function (XMLHttpRequest, Textstatus, Errorthrown) {alert ('Err'); } }); }, //To add a line of competing vehicle systemsaddselect:function (trele) {varTR = $ ('#'+Trele); if(parseint (Jingpinmain.selectcount) <5) { varEle = $ ('<tr></tr>'); varDoc ='<th></th>'; Doc+='<td>'; Doc+='<p style= "Clear:both;" >'; Doc+='<select class= "sel_series brandsel" name= "Fctboxex" title= "click the drop-down button to select the Manufacturer" Onchange= "Jingpinmain.getallseries ( This.value,this); " >'; Doc+='<option value= "0" > select manufacturer </option>'; Doc+='</select>'; Doc+='<select class= "sel_series seriessel" name= "Brboxex" title= "click the drop-down button to select the car" disabled>'; Doc+='<option value= "-1" > select car </option>'; Doc+='</select>'; Doc+='<a style= "display:inline-block;" class= "Cancel" href= "javascript:void (0)" onclick= "Jingpinmain.removeselect (this); " title= "Click X to remove the manufacturer's car system" ></a>'; Doc+='</p>'; Doc+='</td>'; $ (ele). Append (DOC); $ (TR). After (Ele); Jingpinmain.selectcount+=1; //binding manufacturers/car systems varBrandsel = $ (ele). Find ('. Brandsel'); Jingpinmain.getallbrand (Brandsel); } }, //Delete current Option drop-down boxremoveselect:function (obj) {varTR = $ (obj). Parent ('P'). Parent ('TD'). Parent ('TR'); $ (TR). Remove (); Jingpinmain.selectcount-=1; }};
In real-world projects, modular JavaScript