xec*_*onx 2 html css internet-explorer angularjs
我有一个问题,我想只在浏览器不是Internet Explorer的情况下才向项目添加css类.
我可以用Angular JS做到吗?
就像是:
<div ng-class="myClass : "BROWSER IS IE" ? default"><div>
Run Code Online (Sandbox Code Playgroud)
解:
HTML:
<div data-ng-class="getClass()"></div>
JAVASCRIPT:
$scope.isIe = function () {
return false || !!document.documentMode;
}
$scope.getClass = function () {
if ($scope.isIe()) {
return "";
}
else {
return "yourClass1 yourClass2 yourClass3";
}
}
Run Code Online (Sandbox Code Playgroud)
您可以通过以下函数分配类:
data-ng-class="getClass()"
Run Code Online (Sandbox Code Playgroud)
在getClass()实现检测IE的功能并在检测到空字符串时返回空字符串,但如果不是,则返回空格分隔的类名列表.就像是:
编辑:添加功能isIe基于@jsonmurphy的评论
function isIe() {
return false || !!document.documentMode;
}
$scope.getClass = function() {
if(isIe()) {
return "";
}
else {
return "className1 className2 ... ";
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1450 次 |
| 最近记录: |