首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何根据javascript变量转换html头文件的内部文本

如何根据javascript变量转换html头文件的内部文本
EN

Stack Overflow用户
提问于 2017-03-04 20:38:21
回答 1查看 40关注 0票数 0

如果值为9或大于9,则表示良好;如果值在6-9之间,则表示差;如果值小于6,则表示差。如何根据变量值--“浊度”动态改变头部内部文本。示例数据- 9.00

代码语言:javascript
复制
<script>
        FusionCharts.ready(function () {
            LoadChart();
        });

        function LoadChart() {
            $.ajax({
                url: 'https://url', // local address
                type: 'GET',
                crossDomain: true,
                success: function (data) {
                    console.log('xhr success')
                    //if (data.success) {
                    console.log("success");
                    var turbidity = data;
                    if (turbidity >= 9.0) {
                        $('#headerValue').text("Good");
                    }
                    if (turbidity < 9.0 && turbidity > 6.0) {
                        $('#headerValue').text("Normal");
                    }
                    if (turbidity < 6.0) {
                        $('#headerValue').text("Poor");
                    }
                    var phfusioncharts = new FusionCharts({
                        type: 'angulargauge',
                        renderAt: 'ph-container',
                        width: '450',
                        height: '300',
                        dataFormat: 'json',
                        dataSource: {
                            "chart": {
                                "caption": "Turbidity",
                                "lowerLimit": "0",
                                "upperLimit": "12",
                                "showValue": "1",
                                "valueBelowPivot": "1",
                                "theme": "fint"
                            },
                            "colorRange": {
                                "color": [{
                                    "minValue": "0",
                                    "maxValue": "4",
                                    "code": "#6baa01"
                                }, {
                                    "minValue": "4",
                                    "maxValue": "8",
                                    "code": "#f8bd19"
                                }, {
                                    "minValue": "8",
                                    "maxValue": "12",
                                    "code": "#e44a00"
                                }]
                            },
                            "dials": {
                                "dial": [{
                                    "value": turbidity
                                }]
                            }
                        }
                    });

                    phfusioncharts.render();
                    //}
                }
            });
        }
</script>

   <td><h3 align="center">Water Quality  : Good</h3> </td>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-04 21:03:23

通过将id指定给status,将html编写为

代码语言:javascript
复制
  <td><h3 align="center">Water Quality  : <span id="status">Good</span></h3> </td>

现在,当您获得结果时,只需使用js更改文本即可

代码语言:javascript
复制
//Suppose you got data in var named data
if(data >=9 )
{
  document.getElementById("status").innerText="Good"
}
else if(data >=6 && data <9 )
{
   document.getElementById("status").innerText="Bad"
}

else 
{
 document.getElementById("status").innerText="Poor"
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42596116

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档