2012-09-09 134 views
1

我想用valum文件上傳插件使用jquery ui進度條。代碼:如何使用jquery ui進度條?

<div id="pb"></div> 

     ..... 
    onProgress: function (id, fileName, uploadedBytes, totalBytes) { 
     $("#pb").progressbar({ value : uploadedBytes }); 
    }, 
    . .... . 

但是,這不工作,任何人都可以指導我,如何正確使用進度欄?

+1

你有什麼錯誤...? –

+0

不工作的描述太廣泛。這可能只是無關的錯誤,阻止你的腳本工作。 – TigOldBitties

+0

我的回答對你有幫助嗎?讓我知道結果.. – ffffff01

回答

2

假設你有一個<div id="progressbar"></div>

的HTML下面的代碼將通過每10毫秒一次,直到它達到100的進度步驟:

<script type="text/javascript"> 
    var i = 0; //variable used to count the steps 
    function myclick(){ // function called on a button click for example 
     var int = self.setInterval(
      function(){ 
       if (i == 100) window.clearInterval(int); 
       $("#progressbar").progressbar("value", i); 
       i++; 
      } 
      , 10); 
    } 

    $('button').button().click(myclick); // a button element which will 
             // start the progress bar 
    $("#progressbar").progressbar(); //this part sets up the progressbar 
</script> 

注:其他的答案也有效,我只是將此答案作爲「如何正確使用進度條」的答案發布,這是IMO尚未回答的問題的一部分。

1

進度條以百分比表示。您需要將uploadedBtyes轉換爲totalBytes的百分比,然後將其作爲數字傳遞給選項的值屬性。

1

您需要計算上傳的百分比字節數。

var percentValue = (uploadedBytes/totalBytes) * 100 

$("#pb").progressbar({ 
     value: percentValue 
});