jquery 的progressbar
时间: 2023-11-28 21:44:24 浏览: 29
Jquery的progressbar是一个进度条插件,可以用于显示任务的进度。以下是一个简单的例子:
```html
<!DOCTYPE html>
<html>
<head>
<title>jQuery Progress Bar Example</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" />
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<style>
#progressbar {
width: 500px;
margin: 50px auto;
}
</style>
</head>
<body>
<div id="progressbar"></div>
<script>
$(function() {
var progressbar = $("#progressbar");
progressbar.progressbar({
value: false,
change: function() {
progressbar.text(progressbar.progressbar("value") + "%");
},
complete: function() {
progressbar.text("Complete!");
}
});
function progress() {
var val = progressbar.progressbar("value") || 0;
progressbar.progressbar("value", val + 2);
if (val < 99) {
setTimeout(progress, 80);
}
}
setTimeout(progress, 2000);
});
</script>
</body>
</html>
```
这个例子演示了如何使用Jquery的progressbar插件来显示一个进度条。在这个例子中,我们使用了Jquery UI库来加载progressbar插件。在页面加载完成后,我们创建了一个进度条,并设置了一些选项,例如进度条的初始值,以及当进度条的值发生变化时应该执行的回调函数。然后,我们定义了一个progress函数,该函数将进度条的值增加2,并在进度条的值达到100时停止。最后,我们使用setTimeout函数来调用progress函数,以便在2秒后开始更新进度条的值。