In a recruitment website, by limiting the number of job tags selected by users, you can accurately locate the user's position. For example, the user is provided with an alternative position tag in the form of a check box, restricting the user from selecting up to 3, and prohibiting the user from continuing to select when more than three.
Check boxes are used in questionnaire surveys, and recruitment websites are widely used. Today, let’s introduce how to limit the number of options to select at most:
Ideas:
Listen to the onclick event of the checkbox
= function(){ //Code block}
Listen to checked properties of checkbox:
if(){ //Code block}
HTML code:
< input type= "checkbox" name= "sport"/>basketball<br /> < input type= "checkbox" name= "sport"/>football<br /> < input type= "checkbox" name= "sport"/>volleyball<br /> < input type= "checkbox" name= "sport"/>badminton<br/> < input type= "checkbox" name= "sport"/>table tennis<br/> < p>Choose up to three items</p>
JavaScript code:
var sportSelect = ('sport' ), maxNums = 3; for(var i in sportSelect){ sportSelect[i]. onclick = function (){ var _sportSelect = ('sport' ), cNums = 0; for(var i in _sportSelect){ if(i == 'length') break ; if(_sportSelect[i].checked){ cNums ++; } } if(cNums > maxNums){ = false; alert('The maximum number of options is three'); } } }
The implementation code for the most selected items in the above restricted check box is all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.