我正在尝试检索一系列复选框中的值:
$(document).ready(function() {
var folders = document.getElementsByName('note-behaviour-folder-add[]');
for(var x = 0; x < folders.length; x++){
if ((folders[x].type === "checkbox") && (folders[x].checked)) {
alert("Yes!");
}
}
});
虽然命名元素中有数据,但上面的代码似乎没有检索任何数据。我还尝试了 jQuery 替代方案:
var folders = $("[name='note-behaviour-folder-add[]']");
但这变得疯狂并抓住了应用程序中的所有内容。
至于 HTML 本身:
<div class="note-behaviour-folder-box" id="note-behaviour-folder-box-2">
<input type="checkbox" id="note-behaviour-folder-item-2" name="note-behaviour-folder-add[2]" value="2" checked="checked">Plot
<dl>
<dt><label for="note-behaviour-folder-item-select-2">Behaviours</label></dt>
<dd><select name="note-behaviour-folder-item-select-2" class="chzn-select">
<option value="1">List</option>
<option value="2">Paragraph</option>
<option value="3" selected="selected">Chapter</option>
</select></dd>
</dl>
</div>
有任何想法吗?