jquery - 使用 JQuery/JavaScript 将按钮变成进度条

标签 jquery html css button progress-bar

我正在尝试了解如何将按钮变成进度条。例如,在引导按钮中,例如:

<button class="btn btn-large btn-primary" type="button">Load</button>

我目前正在使用经典的 Bootstrap 进度条并通过 JQuery setInterval 刷新它:

<div class="progress progress-striped"><div id="data_loaded" \
class="bar" style="width: 100%;"></div></div>

是否可以将按钮变成进度条 - 使前进的进度填充实际按钮的背景,而不是为进度条使用单独的页面元素?

最佳答案

是的,jQuery 有一个 .replaceWith() 方法。

Description: Replace each element in the set of matched elements with the provided new content and return the set of elements that was removed.

假设你想使用 HTML5 进度条,你可以这样写你的代码: HTML5

<button class="btn btn-large btn-primary" type="button">Load</button>

JS:

$('button').replaceWith('<progress max="100" value="60">\
        <strong>Progress: 60% done.</strong>\
    </progress>');

fiddler :http://fiddle.jshell.net/KQr7S/

关于jquery - 使用 JQuery/JavaScript 将按钮变成进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15019381/

相关文章:

Javascript:如果div包含iframe,则div上的点击事件不会发生

html - 当我转到询问页面时,页脚不会粘在底部

javascript - 航点 Jquery 动画

html - 当定位为静态/相对时,HTML 和 body 标签如何或为何占用视口(viewport)的宽度和高度?

java - 为什么 Java Spring v.2.2.7 不支持请求方法 'POST'?

c# - 需要比较单元格值然后根据结果更改背景

javascript - 为什么 1px 宽度的线在左数不同时看起来不同?

javascript - 滚动列表后 jQuery 鼠标事件不起作用

javascript - 如何根据单个类属性值获取页面上的多个跨度项内容

javascript - 当前幻灯片 + 导航