选中图片后可以直接触发上传?
- js/Jquery
- 时间:2019-01-12
- 3608人已阅读
简介
html部分:
<form id="userInfoForm">
<div class="myAccountlb">
<img src="<if condition='$members[face]'>{$members['face']}<else />
__PUBLIC__/mobile/images/infoImg.png</if>" id="attrPhotoId" style="width: 100%;height: 100%;border-radius: 50%;" > <input type="file" name="face" id="fileId"> </div> </form> jq部分: <script type="text/javascript"> $(function () { $("#attrPhotoId").click(function () { $("#fileId").trigger("click"); }); $("#fileId").change( function () { var data = new FormData($( "#userInfoForm" )[0]); $.ajax({ url: "__APP__/Per/editface", type: 'POST', dataType: "json", data: data, // 告诉jQuery不要去处理发送的数据 processData: false, // 告诉jQuery不要去设置Content-Type请求头 contentType: false, success: function (res) { alert(res.msg); if (res.status == "1") { window.location.reload(); } }, error: function (responseStr) { console.log("上传文件错误!"); } }); }); }); </script>