我正在尝试获取已选中复选框的顺序.
<ul class="dropdown-content checkboxes">
<li><label><input type="checkbox" />Billy</label></li>
<li><label><input type="checkbox" />Jacob</label></li>
<li><label><input type="checkbox" />Bob</label></li>
<li><label><input type="checkbox" />Alexandren</label></li>
<li><label><input type="checkbox" />Erren</label></li>
<li><label><input type="checkbox" />Stewgart</label></li>
<li><label><input type="checkbox" />Jillian</label></li>
<li><label><input type="checkbox" />Other</label></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
我想出了这个但是我无法得到复选框被选中时的顺序.我只能获得仅检查哪些列表.
$(":checkbox").click(function() {
console.log($(":checked").length);
var i = 0;
checked = true;
$(':checkbox').each(function() {
if (this.checked == false) {
i++;
if (i === 8) {
checked = false;
}
}
});
});
Run Code Online (Sandbox Code Playgroud)
我如何获得他们检查的订单数据?例如,"按此顺序检查复选框1,6,3,2"
我试图在列表中的多个列表中获取第一个值,并存储它重复多少次,如果它不止一次进入字典/哈希.
coordinates = [
['bg1955', '47.6740° N', '122.1215° W'],
['bg1955', '47.6101° N', '122.2015° W'],
['bg1955', '47.6062° N', '122.3321° W'],
['sj1955', '37.3318° N', '122.0312° W']
]
Run Code Online (Sandbox Code Playgroud)
当我尝试以下内容时:
my_dict = {row[0]:coordinates.count(row[0]) for row in coordinates}
Run Code Online (Sandbox Code Playgroud)
价值my_dict成为:
{'sj1955': 0, 'bg1955': 0}
Run Code Online (Sandbox Code Playgroud)
代替:
{'bg1955': 3}
Run Code Online (Sandbox Code Playgroud)
我如何在python3中获得上述内容?原始数据样本在一个列表中将有超过20,000个列表,而不是上面列出的4个列表.
编辑:当我提到时certain,我的意思是每一行中的特定位置是行[0],而不仅仅是在字典中返回1个结果.如果有多个不同的值重复,它会导致这个,因为我想存储任何重复的值,让我们说如果sw1950在20个列表中并且jb1994在393个列表中它将是:
{'bg1955': 3, 'sw1950': 20, 'jb1994': 393}
Run Code Online (Sandbox Code Playgroud)