Rails 3:乘以一个数组的所有元素(Ruby: Multiply all elements of an array)
假设我有一个数组A = [1,2,3,4,5]
我如何将所有元素与ruby相乘并得到结果? 1 * 2 * 3 * 4 * 5 = 120
以及如果有一个元素0呢? 我怎样才能忽略这个元素?
Let's say I have an array A = [1, 2, 3, 4, 5]
how can I multiply all elements with ruby and get the result? 1*2*3*4*5 = 120
and what if there is an element 0 ? How can I ignore this element?
原文:https://stackoverflow.com/questions/7050869
更新时间:2022-11-06 15:11
最满意答案
尝试这样的事情:
$(function(){ $('li').click(function(){ $('#parentLi').find('input[type="checkbox"]').prop('checked', true); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <li id="parentLi"> <span class="collapsible"></span> <span>System</span> <ul> <li> <span class="collapsible"></span> <span>Division</span> <ul> <li> <input class="chkGroup" type="checkbox"> </li> </ul> </li> </ul> </li>
Try something like this:
$(function(){ $('li').click(function(){ $('#parentLi').find('input[type="checkbox"]').prop('checked', true); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <li id="parentLi"> <span class="collapsible"></span> <span>System</span> <ul> <li> <span class="collapsible"></span> <span>Division</span> <ul> <li> <input class="chkGroup" type="checkbox"> </li> </ul> </li> </ul> </li>
相关问答
更多-
jquery mobile 页面跳转第二次不刷新怎么办[2022-09-17]
checkbox -
jquery mobile本地和环境中显示问题[2023-06-25]
checkbox -
使用.prop()代替,如果我们用你的代码去比较,像这样: 看看例子jsbin : $("#news_list tr").click(function () { var ele = $(this).find(':checkbox'); if ($(':checked').length) { ele.prop('checked', false); $(this).removeClass('admin_checked'); } else { ele ...
-
如何使用jQuery检查/取消选中子项“li”的子项内的复选框?(How to check/uncheck checkbox inside child of child “li” using jQuery?)[2022-10-21]
尝试这样的事情: $(function(){ $('li').click(function(){ $('#parentLi').find('input[type="checkbox"]').prop('checked', true); }); });尝试这个: $(document).ready(function(){ $('.check:button').toggle(function(){ $('input:checkbox').attr('checked','checked'); $(this).val('uncheck all'); },function(){ $('input:checkbox').removeAttr('checked'); $(this).va ...对于jQuery <1.6: 要检查/取消选中复选框,请使用checked和更改的属性。 使用jQuery可以做到: $('#myCheckbox').attr('checked', true); // Checks it $('#myCheckbox').attr('checked', false); // Unchecks it 因为你知道,在HTML中,它看起来像: