Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html “禁用”为true时更改背景色_Html_Css_Angularjs_Ng Class - Fatal编程技术网

Html “禁用”为true时更改背景色

Html “禁用”为true时更改背景色,html,css,angularjs,ng-class,Html,Css,Angularjs,Ng Class,如何在禁用时更改输入字段的背景色为true。如何对禁用的输入字段使用ng class //html <div> <input type="file" ng-disabled="false" id="id1"> </div> //Controller document.getElementById("id1").disabled = true; //html //控制器 document.getElementById(“id1”).disabled=tru

如何在禁用时更改输入字段的背景色为true。如何对禁用的输入字段使用
ng class

//html
<div>
<input type="file" ng-disabled="false" id="id1">
</div>

//Controller

document.getElementById("id1").disabled = true;
//html
//控制器
document.getElementById(“id1”).disabled=true;

只需禁用ng的范围变量,并将其与ng类一起使用即可

<input type="file" ng-disabled="shouldDisable" ng-class="{'disabledCssClassName' : shouldDisable}" id="id1">


然后在控制器中,通过设置shouldDisable=true/false来管理控制器的禁用状态,并在样式表中定义css类,您不需要ng类,但可以使用ng样式:

 <input type="file" ng-disabled="false" id="id1" ng-style="{'background-color': disabled? 'red' : 'green'}"

下面是一个使用
ng类的示例

angular
.module('应用程序',[])
.controller('ctrl',函数($scope){
$scope.disabled=true;
});

.ng残疾人士{
背景:#E9B96E;
}
残废


这会奏效,但我认为这太复杂了。你不能用css选择器代替angular来完成同样的事情吗?编辑:使用范围变量确定输入是否被禁用是更好的方法。我的评论只涉及问题的样式部分。但是,你正在将演示样式混合到你的内容/模型中,因此,如果你想明年重新调整网站/应用程序的外观,你必须浏览每个文件。最好在
.css
文件中使用外部样式。