2016-11-21 106 views
0

我試圖顯示一個「加載圖像」,而一些處理髮生在background.Following代碼不會隱藏「加載圖像」,一旦頁面加載。是否有這個代碼有問題?javascript to display loading image

#!/usr/bin/python 
# Create instance of FieldStorage 
import cgi 
import subprocess 
import re 
import sys 
import os 
print "Content-type:text/html\r\n\r\n" 
print 
print "<html>" 
print "<head>" 
print "<title>Hello - Second CGI Program</title>" 
print "</head>" 
print ''' 
<style> 
#loading{ 
width: 50%; 
height: 50%; 
top: 0; 
left: 0; 
position: fixed; 
display: block; 
opacity: 0.7; 
background-color: #fff; 
z-index: 99; 
text-align: center; 
} 

#loading-image { 
position: absolute; 
top: 50px; 
left: 140px; 
z-index: 100; 
} 
</style> 
<body> 
<div id="loading"> 
<img id="loading-image" src='../images/loader.gif' alt='Loading...' /> 
</div>''' 

form = cgi.FieldStorage(){ 
    # Get data from fields 
    left: 140px; 
    z-index: 100; 
} 
</style> 

<body> 
<div id="loading"> 
    <img id="loading-image" src='../images/loader.gif' alt='Loading...' /> 
</div>''' 

form = cgi.FieldStorage() 
# Get data from fields 
#caseid=form.getvalue('case',default=None) 
#filename=form.getvalue('filename',default=None) 
caseid='CASE1' 
filename='READ.txt' 
pathtofile='/var/www/py_files/'+caseid+'/'+filename 
#print('PATH TO FILE'+pathtofile) 
destpath='/var/PacketPro/'+caseid+'/'+filename 
#print('DEST PATH'+destpath) 
#result=filetransfer(pathtofile,destpath) 
#print('Result'+str(result)) 
#sys.exit(0) 
#print output 
print ''' 

<h2>Hello </h2> 
<script language="javascript" type="text/javascript"> 
$(window).load(function() { 
    $('#loading').hide(); 
    }); 
</script> 
</body> 
</html>''' 
+0

你錯過了一個jQuery的參考? –

+0

ok。我現在加了它。基本上這個腳本是我的html頁面的表單動作腳本。 –

+0

現在工作嗎? –

回答

0

如果更換

$('#loading').hide(); 

$('#loading').css("display","none"); 

那麼標籤應該有它的顯示樣式設置爲無,這將隱藏它。

如果你想有放回到正常隨時樣式,然後用

$('#loading').css("display","block"); 

道歉,如果有jQuery中這樣做的更好的辦法,我必須承認,我沒有用它多少所以我不太熟悉它