所以我有一组标签,所有属于“BTN BTN-警告”引导类:将类分配唯一ID的所有元素jQuery的
<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>
我想的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++;
});
});
但是,这是行不通的。我究竟做错了什么?
应该是'label.btn-warning',没有空间。 –