简体   繁体   English

如果 data-progress="50" 更改 data-progress-text

[英]if data-progress="50" change data-progress-text

I have a loader on my page and its html looks like this:我的页面上有一个加载器,它的 html 如下所示:

<div class="pace-progress" data-progress-text="Loading 50/100" data-progress="50" style="transform: translate3d(100%, 0px, 0px);">

I want to write a JS that can change the data-progress-text when the data-progress is 50 from "Loading 50 / 100" to "Almost there!"我想编写一个 JS,当data-progress is 50时,可以将data-progress-text"Loading 50 / 100"更改为"Almost there!" . .

I do not know where to start and any help would be greatly appreciated.我不知道从哪里开始,任何帮助将不胜感激。

if ( $('.pace-progress').attr('data-progress-text') == '50' ) {
(".pace-progress").attr("data-progress-text") == "Almost there!"}

== is for comparing a value ==用于比较一个值

= is for assigning a value =用于赋值

That said, since you are using the jQuery attr method you cannot assign a value like that.也就是说,由于您使用的是 jQuery attr方法,因此您无法分配这样的值。 The method itself accepts a second argument to determine if it is a getter or a setter.该方法本身接受第二个参数来确定它是 getter 还是 setter。

The jQuery docs are pretty complete and you should definitely make use of them before asking questions jQuery 文档非常完整,您一定要在提问之前使用它们

Use setInterval to check periodically for the value and update the corresponding attribute:使用 setInterval 定期检查值并更新相应的属性:

setInterval(fucntion(){
   if ( $('.pace-progress').attr('data-progress') == '50' )
      $(".pace-progress").attr("data-progress-text", "Almost there!");
}, 500);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM