所以我使用 ProgressBar JQuery 插件 ( http://t.wits.sg/misc/jQueryProgressBar/demo.php ) 来创建一些静态进度条。
我想要实现的是通过这个标记:
<span class="progress-bar">10 / 100</span>
生成一个进度条,最大值为 100,当前值为 10。我使用 html() 方法获取跨度的内容,然后使用 split() 获取两个数字:
$(document).ready(function() {
$(".progress-bar").progressBar($(this).html().split(' / ')[0], {
max: $(this).html().split(' / ')[1],
textFormat: 'fraction'
});
});
这不起作用,有什么建议吗?
我很确定问题出在 $(this).html().split('/')[0] 和 $(this).html().split('/')[1],这是正确的语法吗?
最佳答案
试试这个:
$(document).ready(function() {
$(".progress-bar").each(function(){
values = $(this).html().split(' / ');
$(this).progressBar(values[0], {
max: values[1],
textFormat: 'fraction'
})
});
});
使用变量进行分割没有任何问题。它实际上节省了您的通话时间。
关于javascript - jQuery:如何从给定的标记生成进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1138515/