How to change input border-color, with jQuery, depending on its value?

后端 未结 3 1984
一生所求
一生所求 2021-02-19 09:25

I have question about jQuery. I have code below which works fine; it changes input border-color depending on its value, which is typed and entered. But

3条回答
  •  终归单人心
    2021-02-19 10:07

    Same issue here. On my case, the input was a table column and it was displayed for every table row. With the next code I managed to change only one input color, not all when I changed the value for one.

             $('input[type=number]').each(function () {
    
                 /* Change border color depending on the input value */
                 var value = parseInt(this.value, 10);
                 if (value != 0) {
                     $(this).css('border-color', function () {
                         return value ? 0 : '#bfbfbf', '#f32d83';
    
                     });
    
                 }
                 else {
                     $(this).css('border-color', '#bfbfbf');
                 }
    
             });
    

    Hope it helps

提交回复
热议问题