Simple and compact multi-level linkage menu implemented with prototype
Source: Internet
Author: User
The simple and compact multi-level linkage menu implemented by prototype uses the prototype. js Library, which can be found on the Internet and is an open-source js function library.
I have posted several posts on the linkage menu today.
Everyone should have their own good code.
I also posted a relatively small code in our team.
// Author: downpour
Var DoubleCombo = Class. create ();
DoubleCombo. prototype = {
Initialize: function (source, target, ignore, url, options, excute ){
This. source = $ (source );
This.tar get =$ (target );
This. ignore = $ A (ignore );
This. url = url;
This. options = $ H (options );
This. source. onchange = this. doChange. bindAsEventListener (this );
If (excute ){
This. doChange ();
}
},
DoChange: function (){
If (this. source. value! = ''){
// First clear the ignore ones
This. ignore. each (
Function (value ){
$ (Value). options. length = 1;
$ (Value). options [0]. selected = 'selected ';
}
);
// Create parameter for ajax
Var query = $ H ({id: this. source. value });
Var parameters = {
Method: 'post ',
Parameters: $ H (this. options). merge (query). toQueryString (),
OnComplete: this. getResponse. bindAsEventListener (this)
}
Var locationRequest = new Ajax. Request (this. url, parameters );
}
},
GetResponse: function (request ){
This.tar get. options. length = 1;
This.tar get. options [0]. selected = 'selected ';
Var response = $ A (request. responseText. trim (). split (';'));
Response. length --;
For (var I = 0; I <response. length; I ++ ){
Var optionParam = response [I]. split (',');
This.target.options+this.tar get. options. length] = new Option (optionParam [1], optionParam [0]);
}
}
}
Let's briefly talk about several parameters:
Source Level 1 Menu
Target linkage menu
When ignore is associated at level 3, for example, a country, province, city, or city without Province in Shanghai, you can ignore the menu at level 3rd.
Url action url
Options action parameter
Is excute linked?
Take a common example to see how the national provincial-Municipal level 3 linkage works.
Code
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.