The shopping cart effect implemented by JavaScript can be used in many places _ javascript skills

Source: Internet
Author: User
The shopping cart effect implemented by JavaScript. Of course, this effect can be used in many places, such as the selection of friends and the human resources module. If you need it, you can refer to the shopping cart effect implemented by JavaScript, of course, this effect can be applied in many places, such as friend selection, human resources module, salary calculation, and personnel selection. Let's take a look at a shopping cart:

Code:

GoodsCar. js: This js is written as a separate file. It mainly controls the list shown above.

The Code is as follows:


Window. onload = function (){
InitStore ();
};
Var goods = ["ham", "beauty", "Yujie", "Mars day tour", "sports car"];
// ============================ Why do you need to define a temporary storage area? ===
Var temps = []; // temporary storage
// Initialize the repository select to add content
Function initStore (){
Var select_store = document. getElementById ("select_store ");
For (var x = 0; x {
// Create an option object
Var optionNode = document. createElement ("option ");
OptionNode. innerHTML = goods [x];
Select_store.appendChild (optionNode );
}
}
//------------------------------------
Function selectGoods (){
// Obtain the select list object of the store.
Var out_store = document. getElementById ("select_store ");
// Obtain the select list object of my items
Var in_store = document. getElementById ("select_my ");
MoveGoods (in_store, out_store );
}
Function deleteGoods (){
// 1. Record the product to be moved
Var in_store = document. getElementById ("select_store ");
Var out_store = document. getElementById ("select_my ");
MoveGoods (in_store, out_store );
}
/*
* Mobile products:
1. inSotre: Move the product to the warehouse
2. outStore: Remove a product from a warehouse
*/
// Move
Function moveGoods (inStore, outStore ){
// ====================== Clear the array cache =============================
Temps = [];
// Obtain all list items in the store cyclically
For (var x = 0; x {
Var option = outStore. options [x];
// Add the selected list items to the temporary array for storage
If (option. selected ){
Temps. push (option); // Add data to the temporary array. To avoid duplication, the array cache should be cleared.
}
}
// 2. Delete the selected item from the store list
// 3. Add the selected product to the shopping cart
For (var x = 0; x {
// Each node has only one parent node.
// Delete and then add
OutStore. removeChild (temps [x]);
// Add
InStore. appendChild (temps [x]);
}
}


The following is the main file;

The Code is as follows:






Insert title here

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.