简体   繁体   中英

javascript/jquery checkbox comparison using “and”

I have a two checkboxes as follows:

<input type="checkbox" name="options_v[]" id="you_pick_v" value="you_pick" />
<input type="checkbox" name="options_v[]" id="owner_picks_v" value="owner_picks" />

I want my javascript function to make another element grey if the boxes are unchecked and black if either box is checked. For some reason, when I try to use "and" or "or" in the if/else statement, my html editor is showing that there is a problem. Am I not allowed to use these comparison operators in javascript? If so, what might you suggest? Sorry if anything that I'm writing is ambiguous.

Here is my javascript function:

$(document).ready(function() {
   $('#you_pick_v, #owner_picks_v')
    .click(function(){
        var ypv = $('#owner_picks_v').is(':checked');
        var opv = $('#owner_picks_v').is(':checked');

    if(ypv == true and opv == true) {
            alert('both checked');

    }

You need to use && instead of and , then || instead of or . This is JavaScript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM