【发布时间】:2014-12-08 01:20:36
【问题描述】:
我正在弹出一个 Bootstrap 模式,允许用户选择多个复选框。然后在我的视图中,我想遍历每个并检查它们是否被选中。
这是我的模式代码:
<div class="modal fade" id="ethnicityModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Ethnicity Targeting</h4>
</div>
<div class="modal-body">
<h5>Select ethnicities that should be included:</h5>
<input type="checkbox" name="caucasian"><label for="#caucasian"> Caucasian</label>
<br>
<input type="checkbox" name="black"><label for="#black"> African American</label>
<br>
<input type="checkbox" name="hispanic"><label for="#hispanic"> Hispanic/Latino</label>
<br>
<input type="checkbox" name="middleEastern"><label for="#middleEastern"> Middle Eastern</label>
<br>
<input type="checkbox" name="pacific"><label for="#pacific"> Pacific Islander</label>
<br>
<input type="checkbox" name="nativeAmerican"><label for="#nativeAmerican"> Native American/Alaskan</label>
<br>
<input type="checkbox" name="other"><label for="#other"> Other</label>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary saveEthnicity" data-dismiss="modal">Save</button>
</div>
</div>
</div>
</div>
在我看来:
events:
"click .saveEthnicity": "saveEthnicity"
saveEthnicity: (e) ->
console.log e.currentTarget.parentElement.parentNode.children[1].children
所以e.currentTarget.parentElement.parentNode.children[1].children 返回子元素数组。但我似乎无法遍历它们。我试过了
e.currentTarget.parentElement.parentNode.children[1].children.each (child) ->
console.log child
但这会引发错误。知道如何获取每个输入,以便在其上执行 .checked() 吗?
【问题讨论】:
标签: javascript jquery twitter-bootstrap backbone.js coffeescript