加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

用AngularJS动态更改css类的属性

发布时间:2020-12-17 09:52:28 所属栏目:安全 来源:网络整理
导读:我搜索但没有找到有关以下的任何答案: 我喜欢通过bootstrap看的例子 css.bs-docs-example { background-color: #FFFFFF; border: 1px solid #DDDDDD; border-radius: 4px 4px 4px 4px; ...}.bs-docs-example:after { background-color: #F5F5F5; border: 1p
我搜索但没有找到有关以下的任何答案:

我喜欢通过bootstrap看的例子

<css>
.bs-docs-example {
  background-color: #FFFFFF;
  border: 1px solid #DDDDDD;
  border-radius: 4px 4px 4px 4px;
  ...
}
.bs-docs-example:after {
  background-color: #F5F5F5;
  border: 1px solid #DDDDDD;
  border-radius: 4px 0 4px 0;
  color: #9DA0A4;
  content: "Title";
  ...
}

但是我需要动态更改.bs-docs-example中的内容
如:

<html>
<div class="bs-docs-example" ng-style="content:'{{ title }}';"
     ng-repeat="title in titles">

你认为这是可能吗?如何 ?

感谢提前.

我使用ng-bind-html做了类似的操作,我没有控制内容,所以我修改一个可以处理它的类
var somecolorvar = "#F00";
$scope.mystyles = ".something:after { color: " + somecolorvar + "; }";

<style ng-bind-html="mystyles"></style>

然后你会得到这样的东西

<style>.something:after { color: #F00; }</style>

编辑:您也可以通过css attr()处理上述问题,这将把属性拉入到内容中

.something:after {
    display: inline;
    content: '- Value ' attr(value);
}

<div class="something" value="123">this is</div>
<div class="something" value="456">this be</div>

你会看到像:

this is - Value 123
this be - Value 456

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读