Javascript 如何使用jquery ui进度条?
我正在尝试使用jQueryUI进度条和valum文件上传插件。代码:Javascript 如何使用jquery ui进度条?,javascript,jquery,jquery-ui,Javascript,Jquery,Jquery Ui,我正在尝试使用jQueryUI进度条和valum文件上传插件。代码: <div id="pb"></div> ..... onProgress: function (id, fileName, uploadedBytes, totalBytes) { $("#pb").progressbar({ value : uploadedBytes }); }, . .... . ..... onProgress:函
<div id="pb"></div>
.....
onProgress: function (id, fileName, uploadedBytes, totalBytes) {
$("#pb").progressbar({ value : uploadedBytes });
},
. .... .
.....
onProgress:函数(id、文件名、uploadedBytes、totalBytes){
$(“#pb”).progressbar({value:uploadedBytes});
},
. .... .
但这不起作用,有人能告诉我,如何正确使用进度条吗?进度条按百分比工作。您需要将
uploadedBtyes
转换为totalBytes
的百分比,然后将其作为一个数字传递给选项的value属性。进度条按百分比工作。您需要将上载的字节数转换为总字节数的百分比,然后将其作为数字传递给选项的value属性。您需要计算上载字节数的百分比
var percentValue = (uploadedBytes / totalBytes) * 100
$("#pb").progressbar({
value: percentValue
});
您需要以百分比计算上载的字节数
var percentValue = (uploadedBytes / totalBytes) * 100
$("#pb").progressbar({
value: percentValue
});
假设您有一个带有
以下代码将每10毫秒通过progressbar一次,直到达到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>
var i=0//用于计算步数的变量
函数myclick(){//例如,在按钮单击时调用函数
var int=self.setInterval(
函数(){
如果(i==100)window.clearInterval(int);
美元(“#进度条”)。进度条(“价值”,i);
i++;
}
, 10);
}
$('button')。button()。单击(myclick);//一个按钮元素,它将
//启动进度条
$(“#progressbar”).progressbar()//此部分设置progressbar
注意:其他答案也是有效的,我只是将此答案作为问题“如何正确使用progressbar”部分的答案发布,IMO尚未回答。假设您的html带有
以下代码将每10毫秒通过progressbar一次,直到达到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>
var i=0//用于计算步数的变量
函数myclick(){//例如,在按钮单击时调用函数
var int=self.setInterval(
函数(){
如果(i==100)window.clearInterval(int);
美元(“#进度条”)。进度条(“价值”,i);
i++;
}
, 10);
}
$('button')。button()。单击(myclick);//一个按钮元素,它将
//启动进度条
$(“#progressbar”).progressbar()//此部分设置progressbar
注意:其他答案也是有效的,我只是将此答案作为问题“如何正确使用progressbar”部分的答案发布,IMO尚未回答。不工作的描述过于宽泛。可能是无关的错误导致脚本无法运行。我的回答对您有帮助吗?让我知道结果……不工作的描述太宽泛了。可能是无关的错误导致脚本无法运行。我的回答对您有帮助吗?让我知道结果。。