JavaScript对比两个百分数大小
标签:
JavaScript
知识点
获取标签font内容
判断两个百分比大小
修改标签font内容颜色
httml表格
代码样例
<!DOCTYPE html><html><head><style type="text/css">*{margin:0;padding:0;}td {text-align:center;}tr {text-align:center;}th {text-align:center;}</style></head><body><script type="text/javascript"> $(document).ready(function(){var sumrequest = document.getElementById('sumrequest').innerText;var avgrequest = document.getElementById('avgrequest').innerText;var errorcount = document.getElementById('errorcount').innerText;var erroravg = document.getElementById('erroravg').innerText;var longtime = document.getElementById('longtime').innerText;var longtimeavg = document.getElementById('longtimeavg').innerText;//强制转换为数值型sumrequest = parseFloat(sumrequest); avgrequest = parseFloat(avgrequest); errorcount = parseFloat(errorcount); erroravg = parseFloat(erroravg); longtime = parseFloat(longtime); longtimeavg = parseFloat(longtimeavg); if (sumrequest < avgrequest) {document.getElementById( "sumrequest" ).style.color = "red"; }if (sumrequest >= avgrequest) {document.getElementById( "sumrequest" ).style.color = "green"; }if (longtime < longtimeavg) {document.getElementById( "longtime" ).style.color = "green"; }if (longtime >= longtimeavg) {document.getElementById( "longtime" ).style.color = "red"; }if (errorcount < erroravg) {document.getElementById( "errorcount" ).style.color = "green"; }if (errorcount >= erroravg) {document.getElementById( "errorcount" ).style.color = "red"; } });</script> <table width="100%" height="100%" cellspacing="0" cellpadding="0"><tr><th><font >请求次数</font></th><th><font >错误次数</font></th><th><font >超长请求</font></th></tr><tr><td> <font size="5" id="sumrequest"> $sumrequest </font> <font size ="5">(</font> <font size="5" id="avgrequest"> $avgrequest </font><font size ="5">)</font> </td><td> <font size="5" id="errorcount"> $errorcount </font> <font size ="5">(</font> <font size="5" id="erroravg"> $erroravg </font><font size ="5">)</font> </td><td> <font size="5" id="longtime"> $longtime </font> <font size ="5">(</font> <font size="5" id="longtimeavg"> $longtimeavg </font> <font size ="5">)</font> </td></tr></table></body></html>
作者:三杯水Plus
链接:https://www.jianshu.com/p/790d47648545
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦