JavaScript implements the shopping cart effect, of course, which can be used in many places with this effect, friend. For example, in the selection, Human resources module. Salary calculation, talent selection, etc... Let's take a look at some cars after work:
Code
Goodscar.js: This JS is written in a separate file. The main control is shown in the list above.
Window.onload=function () {Initstore ();}; var goods=["Ham", "Beauty", "be", "Mars Day Trip", "sports car"];//================== Why should you define a temporary storage area to be clear oh =============var temps=[];//temporary storage// Initialize warehouse Select to add Content function Initstore () {var Select_store=document.getelementbyid ("Select_store"); for (Var x=0;x< goods.length;x++) {//Create option object var optionnode=document.createelement ("option"); optionnode.innerhtml=goods[x]; Select_store.appendchild (Optionnode);}} ------------------------------------function Selectgoods () {//Get the store's select list Object var out_store= document.getElementById ("Select_store");//Gets the select list object of my product var In_store=document.getelementbyid ("Select_my"); Movegoods (In_store,out_store);} function Deletegoods () {//1. Log 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 Goods: 1.inSotre: Move goods into warehouse 2.outStore: Move goods out of warehouse *///move function movegoods (instore,outstore) {//=============== empty array cache = = The ================temps=[];//loop gets all the list items in the store for (Var x=0;x<outstore.options.length;x++) {var option=outstore.options[x];//adds the selected list item to the temporary array to store if (option.selected) {temps.push (option); /temporarily add data to the array. To avoid repetition, the array cache is emptied}}//2. Remove the selected item//3 in the store list. Add the selected product for (Var x=0;x<temps.length;x++) in the shopping cart {//Each node has only one parent node// First delete and then add Outstore.removechild (Temps[x]);//Join Instore.appendchild (Temps[x]);}}
The following is the main file;
<! DOCTYPE html>
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
JavaScript implementation of Shopping cart effects-effects buddy list