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>

 

posted @ 2014-10-27 14:44  若叶知秋  阅读(266)  评论(0编辑  收藏  举报