標籤:accept inpu border 照片 lis color val erro license
提前引 ajaxfileupload.js 外掛程式
<style>
//file設定樣式:變透明,然後讓dd設定樣式代替他;
如果懸浮時需要顯示小手,將font-size設定成0
.uploadImg dl dd{ width:110px;height:31px;line-height:30px;background:#f56d66;border:none;color:#fff;border-radius:3px;margin-top:11px;text-align:center;cursor:pointer;}
.uploadImg .Prove{ position: absolute;bottom:0;left:0; opacity: 0; filter:Alpha(opacity=0); width:110px;height:31px;cursor:pointer;font-size:0 }.uploadImg_list{width:228px;}
</style>
<div class="uploadImg"> <dl class="left"> <dt><img width="112" height="86" id="imghead" data-bind="attr: { src: saleInfoInput.SealPath}" src="~/Content/images/_register/uploadImg.png" /></dt> <dd>點擊上傳<input disabled class="Prove" value="點擊上傳" id="file1" name="file1 " type="file" accept="image/png,image/gif,image/jpeg,image/x-ms-bmp" onchange="ajaxFileUpload(‘file1‘, ‘hiddenSrc‘, ‘imghead‘)" /></dd> </dl> <span class="uploadImg_list left">支援.jpg .jpeg .bmp .gif .png格式照片單張建議不超過3M</span></div>
<script> function ajaxFileUpload(fileElementId, hiddenSrc, imghead) { $.ajaxFileUpload ( { url: ‘/UploadFile/Upload‘, //用於檔案上傳的伺服器端請求地址 secureuri: false, //是否需要安全性通訊協定,一般設定為false fileElementId: fileElementId, //檔案上傳域的ID dataType: ‘text‘, //傳回值類型 一般設定為json success: function (data, status) //伺服器成功響應處理函數 { var arr = data.split(‘{‘); var s = arr[1].split(‘<‘); var json = "{" + s[0]; var source = eval(‘(‘ + json + ‘)‘); if (source.Success) { var pictiureSrc = source.Data; //$("#"+hiddenSrc+"").val(pictiureSrc); $("#" + imghead + "").attr("src", ‘/UploadFile/GetImagefile?fileinfo=‘ + pictiureSrc + ‘&&type=s‘) if(fileElementId==""){ module.viewModel.saleInfoInput.BusinessLicensePath(""); } } }, error: function (data, status, e)//伺服器響應失敗處理函數 { alert(e); } } ) return false; } </script>
效果
點擊上傳
檔案上傳帶縮圖