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

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

Bootstrap 4 如果輸入類(lèi)型文件有值,則在關(guān)閉模式之前顯示確認(rèn)消息

Bootstrap 4 如果輸入類(lèi)型文件有值,則在關(guān)閉模式之前顯示確認(rèn)消息

www說(shuō) 2023-12-04 19:21:14
大家好,你們好嗎,我現(xiàn)在正在開(kāi)發(fā)一個(gè)項(xiàng)目,我想創(chuàng)建一個(gè)簡(jiǎn)單的技巧。我編寫(xiě)了一個(gè)簡(jiǎn)單的 jQuery 代碼,但它仍然無(wú)法按我想要的方式工作。故事說(shuō):如果輸入類(lèi)型文件有一個(gè)值,則在關(guān)閉模式之前顯示帶有“是”或“否”的確認(rèn)消息, 因此如果用戶(hù)想要離開(kāi)頁(yè)面并關(guān)閉模式對(duì)話(huà)框,則應(yīng)該顯示一條確認(rèn)消息,說(shuō)明他是否確定要關(guān)閉模式對(duì)話(huà)框....HTML 代碼:<div class="modal fade" id="modal_a" tabindex="-1" role="dialog" aria-labelledby="modal_aLabel" aria-hidden="true"data-backdrop="static" data-keyboard="false"><div class="modal-dialog modal-dialog-scrollable" role="document"><div class="modal-content"><div class="modal-body">   <div class="uploadavatar">        <input type="file"                class="custom-file-input"                id="ID12"                name="avatar"               value=""               hidden />        <label role="button" class="btn" for="ID12">            Upload Now        </label>    </div></div></div></div></div>JS代碼:$(document).ready(function() {    $(document).on('hidden.bs.modal', '#modal_a', function (e) {        $('#ID12').on('change', function(e){            const FileLength = $(this)[0].files.length;            if(FileLength > 0){                const ConfirmMessage = confirm("Are you sure?");                if(ConfirmMessage){                    $("#ID12").val('');                }            }        });    });});
查看完整描述

2 回答

?
慕神8447489

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

基本上,下面的代碼檢查輸入中是否存在文件......

如果文件存在,則會(huì)發(fā)出確認(rèn)消息。

如果用戶(hù)因?yàn)椴淮_定是否要提交上傳而取消,則模式將不會(huì)關(guān)閉。

但如果上傳文件從未存在于上傳輸入中,則模式將照常關(guān)閉:-)


查看完整回答
反對(duì) 回復(fù) 2023-12-04
?
慕哥6287543

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

// launch the example modal

$('#test-modal').modal('show');


// check for changes on input and force value

$('#test-upload').on('change', function() {


  // force the value in the dom

  $(this).attr('value', $(this).val());


});


// lets run the confirm checks on hide

$(document).on('hide.bs.modal', '#test-modal', function(e) {


  // if upload value is not empty/specified

  if ($('#test-upload').val() != '') {


    // confirm your sure about cancelling upload

    var uploadSure = confirm("You sure you want to cancel your upload?");


    // confirm checks

    if (!uploadSure) {


      // stop modal closing

      e.preventDefault();


    } else {


      // continue closing/hiding modal


    }


  }


});

<div class="modal fade" id="test-modal">

  <div class="modal-dialog modal-dialog-scrollable">

    <form class="modal-content">

      <div class="modal-header">

        <h5 class="modal-title">Upload Confirmation</h5>

        <button type="button" class="close" data-dismiss="modal">

          <span>&times;</span>

        </button>

      </div>

      <div class="modal-body">

        <div class="form-group">

          <input type="file" class="form-control-file" id="test-upload">

        </div>

      </div>

    </form>

  </div>

</div>


<div class="container mt-3">

  <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#test-modal">

    Launch Modal

  </button>

</div>


<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>

<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>


<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet"/>


查看完整回答
反對(duì) 回復(fù) 2023-12-04
  • 2 回答
  • 0 關(guān)注
  • 339 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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