简体   繁体   English

提交表单时显示图像加载的纯 javascript 代码(仅中心图像)

[英]Pure javascript code for show image loading(only image in center ) when submit form

I've searched everywhere both on stackoverflow and on the web. surely it will be so trivial as not to be reported however focusing on the backend I would really need it.我已经在 stackoverflow 和 web 上到处搜索了。当然它会如此微不足道以至于不会被报告但是专注于后端我真的需要它。 Specifically, I would need a pure javascript function to show after form submission (therefore only if the required fields are inserted) and show as a single image in the center and with a white background while waiting for the backend to do the redirects.具体来说,我需要一个纯 javascript function 在表单提交后显示(因此只有在插入必填字段时)并在等待后端进行重定向时在中心显示为单个图像并具有白色背景。 thank you very much and happy new year非常感谢,新年快乐

this is the solution i created after reading some javascript basic book.这是我在阅读一些 javascript 基础书籍后创建的解决方案。 In fact it was simple but like all things it must first be studied.事实上,它很简单,但就像所有事物一样,它必须首先被研究。 I leave it as it will certainly be useful to someone我离开它,因为它肯定对某人有用

    <script type="text/javascript">
const form = document.getElementById('generationLinkForm');
const loadingLottie = document.getElementById('loadingLottie');

    form.addEventListener('submit', (e) => {
        var value = document.getElementById('inputLink').value;
        const preloader = document.querySelector('.link-loading');
        if (value.length > 0) {
              form.classList.toggle('fade-out');
              loadingLottie.classList.toggle('show');
              preloader.classList.remove('d-none');
             }
        else
            e.preventDefault();
         
        });
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM