JavaScript implementation of Shopping cart effects-effects buddy list

Source: Internet
Author: User

JavaScript implements the shopping cart effect. Of course, this effect can be used in many places. Friend's. For example, in the selection. Human Resources module, salary calculation, talent selection, etc... Let's take a look at some cars after work:

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvahlta2luzw==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">

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. Array cache to empty}}//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>

var orders = Document.getelementsbyname ("Myorder"); The following sentence is used incorrectly in the process of writing code//getelementsbytagname: Gets a collection of objects based on the specified element name. var orders=document.getelementsbytagname ("Myorder"); for (Var x=0;x<orders.length;x++) {var order=orders[x];if ( arg== "1") {order.checked=true;} else if (arg== "0") {order.checked=false;} else if (arg== "2") {order.checked=!order.checked;}}} Pay the bill. Here is a demo function Paymoney () {var orders = Document.getelementsbyname ("Myorder") with the amount of all the items popped up in the dialog, and/or the total price var sum=0;for (Var x=0 ; x<orders.length;x++) {var order = Orders[x];if (order.checked) {//OK to buy. Sum=sum+number (Order.value);}} Alert ("You see if you want to pay" +sum+ ");} </script>


JavaScript implementation of Shopping cart effects-effects buddy list

Related Article

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.