文件下载时显示“请稍候”消息或进度条

我使用以下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 '

Notice: This plugin uses Maxmind Geolite databases for better accuracy. Click the download button to install now.

'; 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 ''; } } } }

尝试给你的按钮一个ID,如下所示:

  

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

 

然后我们可以使用基本的jQuery onClick函数并像这样更改’s innerhtml:

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

希望这有助于:)