如何简化jQuery条件?

时间:2022-06-06 11:46:16

I have an OR condition that checks if any of two checkboxes are checked, it works great but I am wondering if there are some other ways of implementing this to simplify code...

我有一个OR条件,检查是否检查了两个复选框中的任何一个,它工作得很好,但我想知道是否有其他方法来实现这个以简化代码...

It would be great if this can be done with defining private class in a varibale. forum_private = $('.private').first().prop("checked") || $('.private').last().prop("checked")

如果可以通过在varibale中定义私有类来完成它将会很棒。 forum_private = $('。private')。first()。prop(“checked”)|| $( '私人')。最后的()。支撑( “选中”)

I tried with forum_private = $('.private').filter(':checked') but this doesn't works.

我尝试使用forum_private = $('。private')。filter(':checked')但这不起作用。

1 个解决方案

#1


1  

You can simplify the statement as

您可以将语句简化为

$('.private:first:checked, .private:last:checked').length >= 1

#1


1  

You can simplify the statement as

您可以将语句简化为

$('.private:first:checked, .private:last:checked').length >= 1