将字符串封闭在< span>标签

发布于 2025-02-03 08:28:45 字数 789 浏览 2 评论 0 原文

我想将“ 课程”更改为“ 歌曲”,因为22 的 0 动态价值会在某人单击按钮时会增加。我已经尝试了此代码,但没有增加数字:

setInterval(() => {
  if ($('#completion-count').length && !$('.completion_count_no_repeat').length) {
    $('#completion-count').empty();
    $("#completion-count").append(`<span id="completion-count" class="font-semibold">0 of 22 Songs Completed</span>`);
  }
}, 1000);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<span id="completion-count" class="font-semibold">0 of 22 Lessons Completed</span>

I wanted to change the "Lessons" into the "Songs", as 0 of 22 dynamic value it will increment as someone clicks the button. I've tried with this code but it isn't incrementing the number:

setInterval(() => {
  if ($('#completion-count').length && !$('.completion_count_no_repeat').length) {
    $('#completion-count').empty();
    $("#completion-count").append(`<span id="completion-count" class="font-semibold">0 of 22 Songs Completed</span>`);
  }
}, 1000);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<span id="completion-count" class="font-semibold">0 of 22 Lessons Completed</span>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月牙弯弯 2025-02-10 08:28:45

您没有增加数字。

您需要保持最后数字的数量,然后将其格式化为字符串:

let index = 0;

setInterval(() => {
  if ($('#completion-count').length && !$('.completion_count_no_repeat').length) {
    $('#completion-count').empty();
    $("#completion-count").append(`<span id="completion-count" class="font-semibold">${index} of 22 Songs Completed</span>`)
  }
  index++;
}, 1000);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<span id="completion-count" class="font-semibold">0 of 22 Lessons Completed</span>

字符串中的卷曲牙套用于模板。 (

You are not incrementing the number.

You need to keep count of the last number and then format it into the string:

let index = 0;

setInterval(() => {
  if ($('#completion-count').length && !$('.completion_count_no_repeat').length) {
    $('#completion-count').empty();
    $("#completion-count").append(`<span id="completion-count" class="font-semibold">${index} of 22 Songs Completed</span>`)
  }
  index++;
}, 1000);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<span id="completion-count" class="font-semibold">0 of 22 Lessons Completed</span>

The curly braces in the string are for templating. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文