javascript - Angular 函数调用在 IE 浏览器中不起作用

标签 javascript html css angularjs internet-explorer

我最近开始研究 UI。所以我在 html 中使用 angularjs。我对 Internet Explorer CSS 样式有一个疑问。我正在使用 Angular 调用来根据字段值决定 div 的背景颜色。它在 chrome 和 firefox 中运行良好。但在 IE 中它给出了一些错误,如下所示

enter image description here

enter image description here

这是我的 HTML 代码

<div class="row" style="border-bottom: 1px solid black; border-top: 1px solid black; padding-top: 5px; padding-bottom: 5px;margin-right:5px;margin-left:5px; margin-bottom: 5px; margin-top: 5px; clear: both; background-color: {{get_color(system.status)}}; position: relative">

这是我的 Angular 函数

$scope.get_color = function(val){

    if (val == '0'){    
        return 'rgb(245,215,215)';
    }
    else{
        return 'rgba(211,211,211,0)';
    }
}

知道我错过了什么吗?

最佳答案

您的 background-color 设置为 {{get_color(system.status)} 的 Angular 表达式,但它应该是 {{get_color(system.状态)}}。请注意末尾缺少的 }

尝试将您的 HTML 更改为:

<div class="row" ng-style="get_color(system.status)" style="border-bottom: 1px solid black; border-top: 1px solid black; padding-top: 5px; padding-bottom: 5px;margin-right:5px;margin-left:5px; margin-bottom: 5px; margin-top: 5px; clear: both; position: relative">

然后在您的 get_color 函数中,执行如下操作:

$scope.get_color = function(val){
    if (val == '0'){    
        return { "background-color": 'rgb(245,215,215)' };
    }
    else{
        return { "background-color": 'rgb(211,211,211,0)' };
    }
}

总而言之,使用 ng-style 并让您的函数返回一个包含您要使用的样式的对象。

关于javascript - Angular 函数调用在 IE 浏览器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39045517/

相关文章:

css - 如何使 colspan 属性应用于特定行而不是所有行?

javascript - 在页面加载之间保存 Canvas

php - 如果我托管 JS 文件,我可以识别嵌入它的 URL 吗?

javascript - 使用js对文本字段进行相互计算

php - 加载大型JQuery图库的解决方案

javascript - 如何在函数完成后使用 jquery 制作动画 - 让第二个函数等待?

html - 垂直对齐div中固定宽度和 float 的文本

html - 表格布局设置为固定,单元格不拉伸(stretch)

javascript - 使 Bootstrap 导航栏中的文本响应

javascript - 界面网页 View 。使用 javascript 替换 css 属性