码迷,mamicode.com
首页 > Web开发 > 详细

在线头像上传(js)

时间:2015-12-29 00:58:47      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:

 

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script src="jquery-1.8.3.min.js"></script>
</head>
<body>
    <div id="divimg" >
   </div>
    <input type="button" name="name" value="上传" id="btnUpload"/>
    <div >
        <img src="" id="selectId" style="width:100px; height:100px" />
    </div>

</body>
</html>
<script>
    $(function (e) {
        var arrImg = ["0.jpg", "1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg",
            "6.jpg", "7.jpg", "8.jpg", "9.jpg", "10.jpg", "11.jpg", "12.jpg"];
        $("#divimg").append(function () {
            for (var i = 0; i < arrImg.length; i++) {
                $("#divimg").append("<img src=‘img/" + arrImg[i] + "‘, style=‘width:100px; height:100px‘ class=‘eachImg‘/><&nbsp;&nbsp;/>");
            }
        });
    //});

    //$(function () {
        $(".eachImg").click(function () {
            var src = $(this).attr("src");
            //alert(src.replace("img/", ""));
            $("#selectId").attr("src", src);
        });

        $("#btnUpload").click(function () {
            var srcimg = $("#selectId").attr("src").replace("img/", "");
            $.ajax({
                type: "POST",
                url: "/Home/DownloadFile",
                contentType: "application/json",
                data: srcimg
            });
        });
    });
</script>

 

在线头像上传(js)

标签:

原文地址:http://www.cnblogs.com/dyxd/p/5084484.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!