在 jQueryUI ProgressBar 中显示值
我已经设置了一个简单的 jQuery UI ProgressBar:
<script type="text/javascript">
$(function() {
$("#progressbar").progressbar({
value: 35
});
});
</script>
<div id="progressbar"> </div>
除此之外,我想在进度栏中显示一些文本(对于初学者,我只使用“值”)。
我似乎无法让它发挥作用。
额外问题:如何设置显示文本的格式(例如颜色、对齐方式)?
I've set up a simple jQuery UI ProgressBar:
<script type="text/javascript">
$(function() {
$("#progressbar").progressbar({
value: 35
});
});
</script>
<div id="progressbar"> </div>
Among other things, I'd like to display some text in the progress-bar (for starters, I'd just use the "value").
I can't seem to get this to work.
Bonus Question: How do I format the displayed text (e.g. color, alignment)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
不要引入另一个元素 (
span
) 和新样式,而是利用已有的元素,如下所示:css("display", "block")
用来处理值为 0 的情况(当值为 0 时,jQuery UI 在元素上设置display: none
)。如果您查看演示的源代码,您会注意到添加了
。您可以简单地在自己的 CSS 中重写此类,例如:
Instead of introducing another element (
span
) and a new style, leverage what is already there like this:The
css("display", "block")
is to handle the case where the value is 0 (jQuery UI sets adisplay: none
on the element when the value is 0).If you look at the source of The demo, you'll notice that a
<div class="ui-progressbar-value">
is added. You can simply override this class in your own CSS, like:我的方法是:
您可以调整 margin-top 和 margin-left ,使文本位于进度条的中心。
然后,您为页面的 javascript 部分中具有类 Progressbar 的元素应用进度条插件
希望这有帮助
The way I did it was:
You can adjust the margin-top and margin-left so that the text is in the center of the progress bar.
Then you apply the progressbar plugin for the elements which have class progressbar in the javascript section of the page
Hope this help
在摆弄了一些解决方案之后,根据这里的答案,我最终得到了这个:
Html:
JS:(
在更新进度条值的函数内部调用)
CSS:
优点:
After fiddling around with some solutions, based on the answers here, I've ended up with this one:
Html:
JS:
(To be called inside the function that updates the progressbar value)
CSS:
Advantages:
该解决方案允许基于文本的灵活宽度以及文本居中、文本样式等。适用于 Chrome、FF、IE8 和 IE8 的兼容模式。没有测试IE6。
Html:
脚本:
CSS:
工作示例: http://jsfiddle.net/hasYK/
This solution allows for a flexible width based on the text as well as centering the text, styling the text, etc. Works in Chrome, FF, IE8, and IE8 in compatibility mode. Didn't test IE6.
Html:
Script:
CSS:
Working sample: http://jsfiddle.net/hasYK/
我用过这个:
I used this: