我如何檢查一組隱藏字段的值,如果它們的值有不同點,我會返回false。但空值和「假」應被視爲平等。只有3個可能的值,空,真和假,但我想把空作爲假。jquery檢查所有隱藏的元素的值的相似性和返回布爾值
我想是這樣
var isTrue = true;
// is there a way to do this in jquery or similar to this?
var values = $("#group input:hidden").distinct().take(2);
if(values.length == 2) {
// only make it false if there is a true in the values.
if(values[0] == 'True' || values[1] == 'True') {
isTrue = false;
}
}
輸出應該像在指數
{values[0] = '', values[1] = 'False'} = true
{values[0] = 'True', values[1] = 'False'} = false
{values[0] = '', values[1] = 'True'} = false
指數可以互換。
實際上,我已經使用$ .each回答了我自己的問題,而您的問題與我的解決方案几乎完全相同,因此我會接受此答案。和+1作爲擴展。 – 2012-02-17 07:58:02