gpt4 book ai didi

javascript - 使用 AngularJS 像 JQuery 一样操作 DOM?

转载 作者:行者123 更新时间:2023-12-02 17:54:56 26 4
gpt4 key购买 nike

我看过教程和其他文章,说在使用 Angular.js 时甚至不要将 jQuery 包含到项目中,以便尽可能彻底地进行转换。但是,我们如何仅使用 Angular 对 css 和 $('.item').css('top', '50px'); 等其他内容进行简单的 DOM 操作? (或者这是不可能的)?

最佳答案

这可以使用 ng-class 指令实现。在你的元素上,你会说:

<div ng-class="{'classWithTop50':myScopeVariable}"></div>

其中 classWithTop50 在 css 中定义为:

.classWithTop50{
top:50px;
}

当 $scope.myScopeVariable 为 true 时,该元素将具有类 .classWithTop50

关于javascript - 使用 AngularJS 像 JQuery 一样操作 DOM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21037911/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com