我用Twitter Bootstrap制作了一组复选框.现在我想做一个"全选"或"取消全选"按钮.我怎么能用JS函数做到这一点?
Twitter Bootstrap文档说使用$().button('toggle')但它不起作用.
这是我的代码片段:
<div class="control-group">
<div class="controls">
<div class="input">
<div class="btn-group">
<label class="btn btn-toggle" for="colors-1-toggle-0">
<input type="checkbox" id="colors-1-toggle-0" name="colors-1[]" value="color_c" />C
</label>
<label class="btn btn-toggle" for="colors-1-toggle-1">
<input type="checkbox" id="colors-1-toggle-1" name="colors-1[]" value="color_m" />M
</label>
<label class="btn btn-toggle" for="colors-1-toggle-2">
<input type="checkbox" id="colors-1-toggle-2" name="colors-1[]" value="color_y" />Y
</label>
<label class="btn btn-toggle" for="colors-1-toggle-3">
<input type="checkbox" id="colors-1-toggle-3" name="colors-1[]" value="color_k" />K
</label>
</div>
</div>
</div></div>
Run Code Online (Sandbox Code Playgroud) 我昨天又发了一篇文章,并没有成功.我现在会尝试重新排序de idea并再次询问,因为我找不到解决方案(我是一个新手,我正在努力尝试).
问题是我正在使用基于Bootstrap的这个模板,这是我可以直接从其中一个文件中看到的代码,我在我的项目中使用的代码:
html片段:
<div class="hide" id="states">
<div class="control-group">
<label class="control-label">Seleccione</label>
<div class="controls">
<label class="checkbox span4">
<input type="checkbox" value="all" id="allstates" name="all"/>Todas
</label>
<label class="checkbox span4">
<input class="states" type="checkbox" value="Caba" id="" name="st[]"/>Ciudad Autónoma de Buenos Aires
</label>
<label class="checkbox span4">
<input class="states" type="checkbox" value="Buenos Aires" id="" name="st[]"/> Buenos Aires
</label>
<label class="checkbox span4">
<input class="states" type="checkbox" value="Catamarca" id="" name="st[]"/> Catamarca
</label>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
经过大量的搜索,我在检查时发现我的代码看起来像这样(片段):
<div class="controls">
<label class="checkbox span4">
<div class="checker" id="uniform-allstates">
<span>
<input type="checkbox" value="all" id="allstates" name="all"> …
Run Code Online (Sandbox Code Playgroud)