小编use*_*083的帖子

在Jquery中分配类唯一ID的所有元素

所以我有一组标签都属于"btn btn-warning"bootstrap类:

<div class = "btn-group" data-toggle = "buttons">
  <label class="btn btn-warning active">
    <input type="radio" checked>QA 71</input>
  </label>
  <label class="btn btn-warning">
    <input type="radio">QA 72</input>
  </label>
  <label class="btn btn-warning">
    <input type="radio">QA 73</input>
  </label>
  <label class="btn btn-warning">
    <input type="radio">QA 74</input>
  </label>
  <label class="btn btn-warning">
    <input type="radio">ST 71</input>
  </label>
  <label class="btn btn-warning">
    <input type="radio">PR/Beta</input>
  </label>
</div>
Run Code Online (Sandbox Code Playgroud)

我想为所有人分配ID,其中一个标记为QA 71 environment1,下一个标记为environment2,等等.这是我的jquery函数:

var count = 1;
var btnid = "";
$(document).ready(function(){
  $("label .btn-warning").each(
    function(){                     
      btnid = "environment"+count;
      $(this).attr("id", btnid);
      count++;
    });
});
Run Code Online (Sandbox Code Playgroud)

但是,这不起作用.我究竟做错了什么?

html javascript css jquery

1
推荐指数
1
解决办法
59
查看次数

标签 统计

css ×1

html ×1

javascript ×1

jquery ×1