我是 angularJs 的新手。需要在/从 js 文件级别将 css 属性分配给组件。在将 css 样式分配给组件后,我保留了调试器。在调试器级别,我可以看到所有应用到组件行为的 css 属性都很好。完成页面加载后,我无法从 js 文件中看到应用的 css。从我这边来说,可能是一些覆盖/删除 css 样式。如何使用 angular/JavaScript/J 查询来实现这一点,非常感谢。
这是我的代码。
通过 AngularJS
angular.element.find('.ctp-textfield')[0].style.width = "75px !important";
angular.element.find('.ctp-textfield')[0]["ng-style"] = "{height: 75px}";
通过 JavaScript
document.getElementById('Idname').style.width = "75px !important";
通过 JQuery
$('#idname')[0].style.width = "75px !important";
$('#idname').style.width = "75px !important";
最佳答案
在 Angular 中进行 DOM 操作的方法是使用指令。上述所有代码片段看起来都没有在指令的 link
函数中运行,因此不会像您预期的那样工作(但没有足够的上下文来说明您在做什么)。
见:
- > https://docs.angularjs.org/guide/directive
- > http://www.sitepoint.com/practical-guide-angularjs-directives/
- > http://www.ng-newsletter.com/posts/directives.html
- > http://www.befundoo.com/university/tutorials/angularjs-directives-tutorial/
- > https://github.com/angular/angular.js/wiki/Understanding-Directives
关于javascript - 如何使用 javascript/angularJs 应用/防止覆盖/覆盖 css/样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25052325/