Dropdown box Multi-level linkage auxiliary JS, optimize your drop-down box

Source: Internet
Author: User

functionIniteselect (Options) {$ ("body"). Initeselect (Options)} (function($) {$.fn. Initeselect =function(options) {varoption = $.extend ({}, {ids: [], Swtype: [], CallBack: [], GUID: "", BaseUrl: "/ashx/dropdowncontrol.ashx", Split: ";", OB J: {}, Isgetfirstdrop:true}, Options);if(Option.ids.length = = 0) {return}Else{if(Option.isgetfirstdrop) {varc =NULL;if(Option.callBack.length > 0) {c = option.callback[0]} Getselectdata (option.ids[0], option. BASEURL, $.extend (Option.obj, {swtype:option.swtype[0], guid:option.guid}), c)} for(vari = 0; i < option.ids.length-1; i++) {bindchange (i, option)}if(!option.isgetfirstdrop && option.ids.length > 1) {$ ("#" + option.ids[0]). Change ()}} };functionBindchange (i, option) {$ ("#" + option.ids[i]). Change (function() {varValue = $ ("#" + Option.ids[i]). Val (); for(varK = i + 1; K < Option.ids.length; k++) {varids = Option.ids[k].split (option.split); for(varm = 0; M < ids.length; m++) {$ ("#" + ids[m] + "> option[value!= '-1 ']"). Remove ()}}varup = i + 1;if(Value = = "-1") {return}varc =NULL;if(Option.callBack.length >= up) {c = Option.callback[up]} GetSelectData2 (option.ids[up], option. BASEURL, Option.swtype[up], value, Option.split, C, Option.obj)}functionGetSelectData2 (IDs, URL, swtypes, V, split, C, obj) {varTeids = Ids.split (split);varTeswtypes = Swtypes.split (split); for(vari = 0; i < teswtypes.length; i++) {if(Teswtypes[i]! = "") {Getselectdata (teids[i], url, $.extend (obj, {swtype:teswtypes[i], guid:v}), c)}} }functionGetselectdata (ID, url, obj, c) {jquerypost (URL, obj,function(Result) {result = eval ("(" + result + ")");varIdobj = $ ("#" + ID); $ ("#" + ID + "> option[value!= '-1 ']"). Remove (); for(vari = 0; i < result.length; i++) {idobj.append ("<option value=" + result[i]. Value + "' >" + result[i]. Text + "</option>")}if(c! =NULL) {Window.settimeout (function() {C ()}, +)}})}) (JQuery);

How to use: Initeselect ({ids: [' Agentid ', ' orgId ', ' schoolid ', ' Departid/classid '], swtype: [' getallagent ', ' getorgdrop ', ' Getschooldrop ', ' Getschooldepart/getschoolclass ']});

The address or query cascade effect is very good, you can specify the parameters and the initial parameters. You can also specify a server-side URL.

Dropdown box Multi-level linkage auxiliary JS, optimize your drop-down box

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.