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