【问题标题】:Show a "Please Wait" Message or a Progress Bar while Files Download下载文件时显示“请稍候”消息或进度条
【发布时间】:2016-06-17 19:08:51
【问题描述】:

我使用以下 WordPress 管理员通知提示用户下载一些文件。我想在文件下载时包含一个进度条或至少一个“正在下载 - 请稍候”消息。

有什么想法吗?

我已经尝试了几种 jQuery 解决方案,但没有任何效果。说到 jQuery,我完全是个菜鸟。

/* Ask user to download GeoIP database files. */
add_action( 'admin_notices', 'lsmi_dl_admin_notice' );
add_action( 'network_admin_notices', 'lsmi_dl_admin_notice' ); // also show message on multisite
function lsmi_dl_admin_notice() {
    $dir = dirname( __FILE__ );
    $localfilev4 = $dir . '/data/GeoIPv4.dat';
    $localfilev6 = $dir . '/data/GeoIPv6.dat';
    $ctx = stream_context_create( array( 'http' => array( 'timeout' => 120 ) ) ); 
    if ( !file_exists( $localfilev4 ) ) {
        if ( current_user_can( 'install_plugins' ) ) {
            echo
            '<div class="notice notice-warning is-dismissible"><p>Notice: This plugin uses Maxmind Geolite databases for better accuracy. Click the download button to install now.
            <form action="" method="get">
            <input type="submit" class="button" name="download" value="download" />
            </div>';
            if($_GET){
                if(isset($_GET['download'])){
                    $newfilev4 = file_get_contents( "https://sourceforge.net/projects/geoipupdate/files/GeoIPv4.dat/download", 0, $ctx );
                    file_put_contents( $dir . '/data/GeoIPv4.dat', $newfilev4 );
                    if ( !file_exists( $localfilev6 ) ) {
                        $newfilev6 = file_get_contents( "https://sourceforge.net/projects/geoipupdate/files/GeoIPv6.dat/download", 0, $ctx );
                        file_put_contents( $dir . '/data/GeoIPv6.dat', $newfilev6 );
                    }
                }
                echo '<meta http-equiv="refresh" content="0">';
            }
        }
    }
}

【问题讨论】:

标签: php jquery wordpress download message


【解决方案1】:

试着给你的按钮一个像这样的 ID:

<input type="submit" class="button" name="download" value="download" id="download" />

也像这样给你的 div 一个 id:

<div class="notice notice-warning is-dismissible" id="download-div">

然后我们可以使用一个基本的 jQuery onClick 函数并像这样更改 'sinnerhtml:

    $("#download").click(
         function () {
             $('#download-div').html("Please wait...");
         }            
     );
 });

希望这会有所帮助:)

【讨论】:

  • 工作就像一个魅力。唯一的变化是将jQuery(document).ready(function($){ 添加到顶部。谢谢!
  • 没问题,我忘了
猜你喜欢
  • 2012-09-12
  • 2015-01-17
  • 2016-07-30
  • 1970-01-01
  • 2014-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-02
相关资源
最近更新 更多