jQuery点击函数更多变量

jQuery click function more variables

您好,我想问一下是否可以添加更多具有逻辑和的变量。这是我的代码,我想使用更多变量,例如:

<input type="checkbox" name="devices[]" value="1">Apple
<br>
<input type="checkbox" name="devices[]" value="2">Blackberry
<br>
<input type="checkbox" name="devices[]" value="3">Blueberry
<br>
<input type="checkbox" name="devices[]" value="4">Orange
<br>
<input type="text" name="fruit">
<button type="submit" class="btn btn-primary" name="odeslat" value="submit"> Submit </button>

JavaScript:

$('button[type="submit"]').attr('disabled', true);
$(function () {
    $('input[value="1"]' || 'input[value="2"]').click(function () {
        if($(this).is(':checked')) {
            $('input[name="fruit"]').on('keyup', function () {
                if($(this).val() != '') {
                    $('button[type="submit"]').removeAttr('disabled');
                } else {
                    $('button[type="submit"]').attr('disabled', 'disabled');
                }
            });
        } else {
            $('button[type="submit"]').attr('disabled', 'disabled');

        }
    });
});

此代码不起作用$('input[value="1"]' || 'input[value="2"]'),我不知道如何修复它。

网络版http://jsfiddle.net/krizvite/hk05wps6/

选择器中没有 OR 条件。

选择器将抛出语法错误。

$('input[value="1"]' || 'input[value="2"]')

您可以使用以下选择器来获取第一个匹配的元素。

$('input[value="1"], input[value="2"]').first()

选择器 $('input[value="1"], input[value="2"]') 选择具有值 1 and/or 2input 个元素。如果两个元素都存在,则两者都将被选中。要获取第一个选定的元素,请在选择器上使用 first()