gpt4 book ai didi

javascript - 两个 Action 不能同时进行

转载 作者:可可西里 更新时间:2023-11-01 13:01:58 24 4
gpt4 key购买 nike

我正在尝试使用数据属性制作进度条,但在 Jquery 中,这两个操作不能同时执行。

<div class="progressbar">
<div class="progressvalue" data-percent="50"></div>
</div>
.progressbar {
background: #9696A0;
height: 20px;
border-radius: 10px;
color: #fff;
text-align: center;
font-size: 14px;
position: relative;
z-index: 3;
}
.progressvalue {
background: #4650C8;
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 0;
z-index: -1;
border-radius: 10px;
}
$('.progressvalue').each(function() {
var $this = $(this);
$this.css('width', $this.data('percent') + '%');
$this.parent().text('tournament progress: ' + $this.data('percent') + '%');
});

结果是:

enter image description here

但应该是:

enter image description here

最佳答案

您有两个问题。这是一个可行的解决方案。 https://jsfiddle.net/usyL2vcw/1/

您的第一个问题是您使用的是 this 而不是 $this。您的第二个问题是您不能更改具有子项的 divtext(您可以,但它会替换子项)。请改用兄弟跨度。

<div class="progressbar">
<div class="progressvalue" data-percent="50"></div>
<span></span>
</div>

$('.progressvalue').each(function() {
var $this = $(this);
$this.css('width', $this.data('percent') + '%');
$this.siblings().text('tournament progress: ' + $this.data('percent') + '%');
});

关于javascript - 两个 Action 不能同时进行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37931287/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com