zoukankan      html  css  js  c++  java
  • js实现上传图片预览,购物车加减

    js效果(一):上传的图片预览

    $("#path").change(function(){
      var objUrl = getObjectURL(this.files[0]) ;
      console.log("objUrl = "+objUrl) ;
      if (objUrl) {
        $("#img0").attr("src", objUrl) ;
      }
    }) ;
    //建立一個可存取到該file的url
    function getObjectURL(file) {
      var url = null ; 
      if (window.createObjectURL!=undefined) { // basic
        url = window.createObjectURL(file) ;
      } else if (window.URL!=undefined) { // mozilla(firefox)
        url = window.URL.createObjectURL(file) ;
      } else if (window.webkitURL!=undefined) { // webkit or chrome
        url = window.webkitURL.createObjectURL(file) ;
      }
      return url ;
    }
    <img src="images/head_int_03.gif" id="img0">
    <input type="file" id="path" &nbsp;name="path" style="display:none" onchange="upfile.value=this.value" multiple="multiple">

    购物车加减功能:

    <script>
            $(function(){
                $(".add").click(function(){
                    var t = $(this).parent().find(".text_box");
                    t.val(parseInt(t.val())+1)
                    setTotal();
                })
                $(".min").click(function(){
                    var t = $(this).parent().find(".text_box")
                    t.val(parseInt(t.val())-1)
                    setTotal();
                })
                function setTotal(){
                    $("#total").html((parseInt(t.val())*3.95).toFixed(2));
                }
                setTotal();
            })
        </script>
  • 相关阅读:
    C_数据结构_栈
    C_数据结构_链表
    C_数据结构_数组的修改和删除
    C_数据结构_数组
    Python_闭包_27
    Python_函数的镶嵌和作用域链_26
    P1428 小鱼比可爱
    P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows
    P2946 [USACO09MAR]牛飞盘队Cow Frisbee Team
    codevs 2173 忠诚
  • 原文地址:https://www.cnblogs.com/sakura-Master/p/4054165.html
Copyright © 2011-2022 走看看