This time I will show you how to use AngularJS to switch tabs and tabs. What are the things to note?The following is a practical case, let’s take a look. .
Tab one:
##JavaScript html css
nbsp;html> <meta> <title> js标签页tab切换</title> <style> #p1 .active{ background:blue; } #p1 p{ width:200px; height:200px; background:gray; border:1px solid black; display:none; } </style> <script> window.onload=function (){ var op=document.getElementById('p1'); var aBtn=op.getElementsByTagName('input'); var ap=op.getElementsByTagName('p'); for(var i=0;i<aBtn.length;i++){ //遍历p1中的按钮 aBtn[i].index=i; //给aBth[]添加自定义属性 aBtn[i].onclick=function (){ for(var i=0;i<aBtn.length;i++){ //遍历按钮,将class清除 aBtn[i].className=''; ap[i].style.display='none'; } this.className='active'; ap[this.index].style.display='block'; } } } </script> <p> <input> <input> <input> <input> </p><p>111</p> <p>222</p> <p>333</p> <p>444</p>
Tab two:
angularjs directives: ng-class, ng-click, ng-ifnbsp;html> <meta> <title>AngularJS标签页tab切换</title> <style> .active { background-color: orange; } </style> <script></script> <p> <button>张三</button> <button>李四</button> <button>王五</button> </p> <p> </p><p>张三的个人信息</p> <p>李四的个人信息</p> <p>王五的个人信息</p> <script> var app = angular.module('s1.app', []); app.run(function ($rootScope) { $rootScope.data = { current: "1" // 1代表张三,2代表李四,3代表王五 }; $rootScope.actions = { setCurrent: function (param) { $rootScope.data.current = param; } } }) </script>
Tab three:
angularjs command: ng-class, ng-click, ng-shownbsp;html> <meta> <title> <script></script> </title> <section> <ul> <li> <a>1111111111</a> </li> <li> <a>2222222222</a> </li> <li> <a>33333333333</a> </li> </ul> <!--是否点击--> {{panel.isSelected(1)}} {{panel.isSelected(2)}} {{panel.isSelected(3)}} <p> </p> <h1 id="我是">我是1111111111111111111111</h1> <p> </p> <h1 id="我是">我是22222222222222222</h1> <p> </p> <h1 id="我是">我是3333333333333333333333</h1> </section> <script> var app = angular.module("myApp", []); app.controller("myCtrl", function () { this.tab = 2;/*设置默认*/ this.selectTab = function (setTab) {/*设置tab点击事件*/ this.tab = setTab; }; this.isSelected = function (checkedTab) {/*页面的切换*/ return this.tab === checkedTab; } }); </script>
Tab four:
angularjs commandThe second and third methods are derived from the improvement of the following code, and the effects are the same .nbsp;html> <meta> <title>AngularJS标签页tab切换</title> <script></script> <section> <ul> <li> <a>1111111111</a> </li> <li> <a>2222222222</a> </li> <li> <a>33333333333</a> </li> </ul> <!--是否点击--> {{tab===1}} {{tab===2}} {{tab===3}} <p> </p> <h1 id="我是">我是1111111111111111111111</h1> <p> </p> <h1 id="我是">我是22222222222222222</h1> <p> </p> <h1 id="我是">我是3333333333333333333333</h1> </section> <script> var app = angular.module("myApp", []); app.controller("myCtrl", function () { }); </script>
But there is a difference between ng-show and ng-if
The first difference is,
ng-if This dom node is only created when the subsequent expression is true.
ng-show is created initially, use
display:block and
display:none to control display or non-display.
The second difference is that
ng-if will (implicitly) generate a new scope,
ng-switch The same goes for ,
ng-include, etc. that will dynamically create an interface.
ng-model in
ng-if , and binding this model to another display in the outer layer p Area, when the inner layer changes, the outer layer will not change synchronously, because there are already two variables at this time.
<p>{{name}}</p> <p> <input> </p>ng-show does not have this problem because it does not come with a first-level scope. The way to avoid this kind of problem is to always bind the elements in the page to the properties of the object (
data.x) rather than directly to the basic variables (
x)superior. Scope in AngularJS
How to deal with the failure to install nmp Taobao image on Mac
How to operate Koa2 WeChat public account development Setting up a local development and debugging environment
The above is the detailed content of How to implement tab switching using AngularJS. For more information, please follow other related articles on the PHP Chinese website!

JavaScript core data types are consistent in browsers and Node.js, but are handled differently from the extra types. 1) The global object is window in the browser and global in Node.js. 2) Node.js' unique Buffer object, used to process binary data. 3) There are also differences in performance and time processing, and the code needs to be adjusted according to the environment.

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
