简体   繁体   English

当我使用AngularJS单击其他元素时如何更改元素上的类?

[英]How do I change class on element when I click a element elsewhere using AngularJS?

I'm new to AngularJS and I've been looking for a basic example, where when I click a link, a class is added/removed from another element elsewhere on the page? 我是AngularJS的新手,我一直在寻找一个基本的示例,当我单击链接时,是否在页面上其他位置的其他元素中添加/删除了一个类?

Any help would be greatly appreciated as I would really like to get my head around AngularJS basics. 任何帮助将不胜感激,因为我非常想了解AngularJS基础知识。

Thanks 谢谢

Here's an example that will work within the same controller, and makes use of ng-click , ng-class and a scope variable classOn (generated inline): 这是一个将在同一控制器中工作的示例,并使用ng-clickng-class和范围变量classOn (内联生成):

 .on { color: green; } 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app> <a ng-click="classOn = !classOn">Click me</a> <p ng-class="{on: classOn}">I'm being toggled</p> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击下一个/上一个按钮时,如何将活动类更改为LI元素? - How do I change the active class to the LI element when I click next/previous button? 单击动作时如何更改元素的位置 - How to change the position of an element when I do a click action 使用jQuery,当我在输入框之外单击时如何更改输入元素的值? - Using jQuery, how do I change the input element's value when I click outside of the input box? 单击angularjs中的另一个元素时,如何模拟对元素的单击 - How do I simulate a click on an element when clicking on another element in angularjs 单击元素的子元素时更改状态(+ AngularJS) - Change status when I click in the child of an element (+AngularJS) 当我使用jQuery单击其他元素时如何向元素添加类 - how to add a class to an element when i click a different element with jquery 如何在焦点元素“ A”上更改元素“ B”的类名 - How do I change the class name of element “B” onFocus element “A” 将类应用于单独的元素时,如何更改元素? - How can I change an element when a class is applied to a separate element? 当我单击反应中的按钮时,如何定位和更改不同元素的样式 - How do I target and change the style of a different element when I click a button in react 在AngularJS中,如何一次在一个元素上切换一个类? - In AngularJS, how do I toggle a class on one element at a time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM