Jquery Focus on input field

后端 未结 5 1395
误落风尘
误落风尘 2020-12-29 02:08

The HTML on the page has 20 fields each named and given ID\'s in increasing order from 1 to 20.

If the variable id is set to

5条回答
  •  醉话见心
    2020-12-29 02:42

    You should parse the text inside the input to compare it with a number. var input = parseInt($(this).val()); '

       $(":input").blur(function(){
            var input = parseInt($(this).val());
            var id    = $(this).attr('id');
            if(input > 10){ 
                alert('You must enter a number between 0 and 10 '+id);
                $("#"+id).select();
            }
        });
    

提交回复
热议问题