【问题标题】:Show Loading Gif On Click Submit Button单击提交按钮时显示加载 Gif
【发布时间】:2020-01-30 13:23:49
【问题描述】:

我正在为我的网站使用上传图片插件,当用户在移动设备上单击提交时,他们看不到任何进度,因此他们一次又一次单击提交按钮,我收到太多相同的帖子,我想显示加载 gif当他们点击提交按钮时的图像,这是插件表单

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

\\rest code here

<input type="submit" class="usp-submit" id="user-submitted-post" name="user-submitted-post" value="<?php esc_attr_e('Submit Post', 'usp'); ?>">
</form>

我已经尝试过在堆栈上找到的这个,但它没有用

<img src="https://www.punjabidharti.com/wp-content/plugins/wp-email/images/loading.gif" id="img" style="display:none"/ >

    <script type="text/javascript">
    $('#usp_form').submit(function() {
    $('#img').css('visibility', 'visible');
});</script>

这是我上传图片的网址

https://www.punjabidharti.com/upload-pictures/

希望你能帮帮我

【问题讨论】:

    标签: javascript wordpress forms loading form-submit


    【解决方案1】:

    在布局文件中使用带有display: none 的div,并在需要时将其设置为display:block

    <div style="z-index: 5000; display:none;" id="loadingDiv">
        <table style="margin: 0px auto;">
            <tr>
                <td style="padding-top:200px;" align="center"><img src="https://www.punjabidharti.com/wp-content/plugins/wp-email/images/loading.gif" alt="loading image"/></td>
            </tr>
        </table>
    </div>
    
    $('#usp_form').submit(function() {
        // javascript way
        document.getElementById("loadingDiv").style.display = 'block';
        // jquery way
        $('#loadingDiv').show();  
    });
    

    更新

    layout level files can be any of following:
    
    layout.html
    index.html
    header.html
    footer.html
    

    您可以尝试其他 gif 图片,例如 https://i.stack.imgur.com/rBLb3.gif

    【讨论】:

    • 我多年来一直使用相同的 sn-p !检查它是否在您的 DOM 中正确加载?
    • 不要忘记将 div 放在顶级文件中。
    • 它可以工作,但在图像上传时加载 gif 不旋转
    • 我用你的图片测试了它,旋转正常。你能用CTRL+SHIFT+R重新加载你的页面看看会发生什么吗?
    • 在桌面上它工作正常,但在移动上它不旋转
    【解决方案2】:

    您在 img 中添加了 'style="display:none"' 但在您正在执行的代码中:

    $('#img').css('visibility', 'visible');
    

    你应该这样做:

    $('#img').css('display', 'inline-block');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-16
      • 2018-08-27
      • 2015-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多