Changing CSS based on the value

前端 未结 4 1506
一整个雨季
一整个雨季 2021-01-22 10:58

I have been asked to implement a small validation on values and if the values are greater or less than 0 i need to change or add/remove the css for the td and i tag

My t

4条回答
  •  梦谈多话
    2021-01-22 11:34

    Use JavaScript parseFloat for parsing percentage (http://www.w3schools.com/jsref/jsref_parsefloat.asp).

    var percent = $('#sdlyvar').text();
    var result = parseFloat(percent) / 100.0;
    
    if (result < 0){
        $('#sdlyvar').removeClass("fa-level-up");
        $('#sdlyvar').addClass("fa-level-down")
    } else {
        $('#sdlyvar').removeClass("fa-level-down");
        $('#sdlyvar').addClass("fa-level-up")
    }
    

提交回复
热议问题