In real-world projects, modular JavaScript

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.