[英]change radar color on condition using existing js file variable
I have a radar_box div which is color #7eb6ff, i want to change the color to red if the jsonstr value in external javascript file is above 100. my code is so far doing nothing:我有一个radar_box div,颜色为#7eb6ff,如果外部javascript文件中的jsonstr值高于100,我想将颜色更改为红色。到目前为止,我的代码什么也没做:
html: html:
<script type="text/javascript" src="../declare.js"></script>
<section id="alert">
<h1>alert</h1><br><br>
<div class="radar_box_area">
<div class="radar_box" id="radar_box">
<div class="radar"></div>
</div>
</div>
<script>
var mmm=document.getElementById("radar_box");
function cond(){
if(jsonstr > 100){
mmm.style.backgroundColor("red");
}}
</script>
</section>
my declare.js file:我的 declare.js 文件:
var jsonstr = ["131.05\r\n"]
if the solution is to write my condition in js file, i can't do it because declare.js is created when i run python code.如果解决方案是将我的条件写在 js 文件中,我不能这样做,因为 declare.js 是在我运行 python 代码时创建的。 so the whole file is rewritten.
所以整个文件被重写。
in cond
function use this snippet.在
cond
函数中使用此代码段。 what we done here is just replace any spaces
, convert return str to number
by using +
sign and then compare with value.我们在这里所做的只是替换任何
spaces
,使用+
号将返回 str 转换为number
,然后与值进行比较。
var jsonstr = ["131.05\r\n"];
const check = +jsonstr[0].replace(/(\r\n|\n|\r)/gm, '')
if (check > 100) {
console.log('in', check)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.