第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

將文件上傳到 html 輸入時(shí)如何自動(dòng)加載?

將文件上傳到 html 輸入時(shí)如何自動(dòng)加載?

當(dāng)我將文件放入 html 輸入中時(shí),我想通過(guò) ajax post 上傳。(無(wú)需點(diǎn)擊)它在我單擊當(dāng)前代碼中的啟動(dòng)按鈕后起作用。我的代碼    $(document).ready(function () {  $("#but_upload").click(function () {    $('#img-loag-scrin').html('');    $('div#img-loag-scrin').css('display', 'block').prepend('<img id="img_akb" src="https://' + HTTP + '/images/ajax-loader.gif" id="buff-load" style="display:block;margin:10px auto; cursor: wait;">');    var fd = new FormData();    var files = $('#file')[0].files[0];    fd.append('file', files);    $.ajax({      url: 'https://localhost.uz/ajax/ajax_img.php?act=upload',      dataType: "json",      type: 'post',      cache: false,      data: fd,      contentType: false,      processData: false,      success: function (response) {        if (response != 0) {          $('#img-loag-scrin').prepend(response.scrins);          $('#textrea').val($('#textrea').val() + " " + response.textrea);          $('#img_akb').remove();        } else {          alert('File not uploaded');        }      }    });  });});HTML代碼<form method="post" action="" enctype="multipart/form-data" id="myform">  <input type="file" id="file" name="file">  <input type="button" class="sf_button" value="Upload" id="but_upload"></form>當(dāng) html 插入到輸入文件中時(shí),無(wú)需單擊按鈕,就應(yīng)該加載該文件。加載圖像后,圖像必須從輸入中消失
查看完整描述

1 回答

?
慕俠2389804

TA貢獻(xiàn)1719條經(jīng)驗(yàn) 獲得超6個(gè)贊

我用過(guò)改變。


$(document).ready(function () {

  $('#file').unbind().on('change', function () {

    $('#img-loag-scrin').html('');

    $('div#img-loag-scrin').css('display', 'block').prepend('<img id="img_akb" src="https://' + HTTP + '/images/ajax-loader.gif" id="buff-load" style="display:block;margin:10px auto; cursor: wait;">');

    var fd = new FormData();

    var files = $('#file')[0].files[0];

    fd.append('file', files);

    $.ajax({

      url: 'https://localhost/ajax/ajax_img.php?act=upload',

      dataType: "json",

      type: 'post',

      cache: false,

      data: fd,

      contentType: false,

      processData: false,

      success: function (response) {

        if (response != 0) {

          $('#img-loag-scrin').prepend(response.scrins);

          $('#textrea').val($('#textrea').val() + " " + response.textrea);

          $('#img_akb').remove();

        } else {

          alert('File not uploaded');

        }

      }

    });

  });

});

html代碼


<form method="post" action="" enctype="multipart/form-data" id="myform">

   <input type="file" id="file" name="file">

</form>


查看完整回答
反對(duì) 回復(fù) 2023-09-18
  • 1 回答
  • 0 關(guān)注
  • 92 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)