简体   繁体   中英

See if a number is equal to 1 or every 5th number

I want to check if a number is equal to 1 or every 5th number after that. Eg. 1,6,11,16,21,... Then I want to set a value. Something like

if (checkForOneOrFifth(rowNumber)){
$("#x"+rowNumber+"_Location").val('myText');
$("#x"+rowNumber+1+"_Location").val('myText');
$("#x"+rowNumber+2+"_Location").val('myText');
$("#x"+rowNumber+3+"_Location").val('myText');
$("#x"+rowNumber+4+"_Location").val('myText');
}
var checkForOneOrFifth = function(number) {
if(something here){
return true;
}else{
return false;
}
};

Thanks for any help Scott

You can use the mod operator to check that for you:

var checkforoneorffith = function(number){
  return (number - 1) % 5 == 0;
}

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