This is my own instruction document for the jquery-based picklist plug-in. I hope to share it with you.
Refer to my previous log http://blog.csdn.net/gengv/archive/2010/04/20/5508707.aspx
Plug-ins and demo
: Http://code.google.com/p/jquery-picklist/downloads/list
Main features:
- Support for jquery 1.3 or later is required;
- Multiple options are supported, such as <div> and ;
- You can define fully-free jquery selectors and CSS styles for child components;
- Supports CTRL and shift operations;
- Supports multiple Event Callback callbacks.
Example 1:
Using picklist is actually very simple. It provides the default settings.
It is a picklist. For clarity, the above list is now called List A, and the following list is called list p.
First, introduce the JS files of jquery and picklist to the page:
<SCRIPT type = "text/JavaScript" src = "http://code.jquery.com/jquery-latest.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "http://jquery-picklist.googlecode.com/files/jquery.pickList-0.1.7.pack.js"> </SCRIPT>
Then, declare the picklist in $ (function. Two methods:
$ (Function () {<br/> // 1st methods <br/> var pl_1 = $ ("# picklistcontainer "). picklist (); <br/> // 2nd methods <br/> var pl_2 = new $. picklist (); <br/>}
Both methods are based on the default settings, namely:
- The default jquery selector of list A is
"# Availablelist ";
- The default separator for the p list is
"# Pickedlist ";
- Default items in the list
Select "Li ";
- Default Value of the Add button
Select "# btnadd ";
- Default Remove button
Select "# btnremove ";
- The default CSS style name for hovering is "hoveritem ";
- The default CSS style name is "selecteditem ".
These default options do not need to be declared, and picklist will be used by default. If you need them, you can use the options parameter of picklist () to customize these settings (specific usage will be introduced later ).
The two methods for declaring picklist have the following differences:
The first method is to find the corresponding list selector and button selector in the $ ("# picklistcontainer") object to form the picklist component;
The second method is to directly find the corresponding list selector and button selector under <body> to form the picklist component.
Therefore, we recommend the first method.
The simplest procedure is as follows:
- Introduce jquery and picklist JS files;
- Define the control name and CSS class name in HTML and CSS based on the default selector and CSS class name;
- Declare the picklist component in JavaScript.
Easy to use ~~~
Complete code for the first example:
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> gengv's picklist-demo </title>
<SCRIPT type = "text/JavaScript" src ="Http://code.jquery.com/jquery-latest.js
"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src ="Http://jquery-picklist.googlecode.com/files/jquery.pickList-0.1.7.pack.js
"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
$ (Function (){
$ ("# Sample_1"). picklist ()
;
});
</SCRIPT>
<Style type = "text/CSS">
. Samplediv ul {
Text-Decoration: none;
List-style: none;
Padding: 0;
}
. Hoveritem {
Background: # 6cc;
}
. Selecteditem {
Background: # FC3;
}
# Sample_1 ul {
Width: 280px;
Height: 120px;
Overflow: auto;
Border: 1px solid #609;
}
# Sample_1 span {
Margin: 0 10px;
}
</Style>
</Head>
<Body>
<H3> the first sample
<Div id = "sample_1" class = "samplediv">
<Ul id = "availablelist">
<Li>
<SPAN class = "idcol"> 1 </span> <span> dog </span>
</LI>
<Li>
<SPAN class = "idcol"> 2 </span> <span> CAT </span>
</LI>
<Li>
<SPAN class = "idcol"> 3 </span> <span> mouse </span>
</LI>
<Li>
<SPAN class = "idcol"> 4 </span> <span> goat </span>
</LI>
<Li>
<SPAN class = "idcol"> 5 </span> <span> horse </span>
</LI>
<Li>
<SPAN class = "idcol"> 6 </span> <span> donkey </span>
</LI>
<Li>
<SPAN class = "idcol"> 7 </span> <span> caw </span>
</LI>
</Ul>
<Input id = "btnadd" type = "button" value = "+ Add"/>
<Input id = "btnremove" type = "button" value = "-Remove"/>
<Ul id = "pickedlist">
</Ul>
</Div>
</Body>
</Html>
The picklist plug-in also has many custom options and API functions. We will continue to share them in the next article ~