Angularjs has secondary linkage with add and delete options
This time I will bring you angularjs with add and delete options for secondary linkage. Angularjs has add and delete options for secondary linkage. What are the precautions?. Here is a practical case. Let’s take a look.
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>www.jb51.net 省市二级联动</title> </head> <style> *{ margin:0; padding:0; } .ul{ list-style:none; display:inline-block; } .selectOption ul li{ display:inline-block; width:50px; padding:5px; } ul li:hover{ background-color:#59C0F3; color:#fff; cursor:pointer; } .container{ display:inline-block; } dl{ display: inline-block; } dl dt{ display: inline-block; } .container{ position:relative; text-align: left; vertical-align:top; } .selectBoder{ width:150px; height:20px; margin:0 auto; margin-bottom:5px; cursor:pointer; border:1px solid #808080; padding:2px 5px; font-size:14px; } .selectBoder:hover{ border-color:#59C0F3; } .selectOption:before{ width: 0; height: 0; border-bottom: 50px solid #ffffff; border-left: 50px solid transparent; border-right: 50px solid transparent; } .selectOption{ font-size:14px; position:absolute; background-color: #ffffff; z-index:9999; border:1px solid #eee; width:360px; padding:3px 5px; box-shadow: 5px 5px 10px #888888; } .button{ width:30px; height:30px; display: inline-block; background-color:#59C0F3; text-align:center; line-height: 25px; cursor:pointer; font-size:24px; color:#fff; margin:0 5px; border-radius:30px; } .button:hover{ background-color:#12bb16; } </style> <body ng-app="myApp" ng-controller="myControl"> <p class="inline" ng-repeat = "option in options"> <p class="container"> <dl> <dd class="selectBoder" ng-click="choseP($index)" ng-value="false">{{option.province}}</dd> <dt class="selectOption" ng-if="option.ifShowProvince" ng-mouseleave="leaveProvince(option)"> <ul> <li ng-repeat = " x in province" ng-value="x.value" ng-click="choseProvince($event.target,option)" data-name="{{x.name}}">{{x.name}}</li> </ul> </dt> </dl> </p> <p class="container"> <dl> <dd class="selectBoder" ng-click="choseC($index)" ng-value="false">{{option.city}}</dd> <dt class="selectOption" ng-if="option.ifShowCity" ng-mouseleave="leaveCity(option)"> <ul> <li ng-repeat = "y in option.cities" ng-value="y.value" ng-click="choseCity($event.target,option)" data-name="{{y.name}}">{{y.name}}</li> </ul> </dt> </dl> </p> <span class="button" ng-click="addChose($index)">+</span> <span class="button" ng-click="deleteChose($index)">-</span> </p> </p> </body> <script type="text/javascript" src="../js/jquery-1.8.3.js"></script> <script type="text/javascript" src="../js/angular.min.js"></script> <script type="text/javascript"> var app = angular.module('myApp',[]); app.controller('myControl',function($scope){ $scope.ifShowCity = false; $scope.ifShowProvince = false; $scope.options =[{index:"0",ifShowCity:false,ifShowProvince:false,province:"",city:"",cities:""}]; $scope.leaveProvince = function(option){ $.each($scope.options,function(index,item){ if(option == $scope.options[index]){ $scope.optionIndex = index; } }) $scope.options[$scope.optionIndex].ifShowProvince = false; } $scope.leaveCity = function(option){ $.each($scope.options,function(index,item){ if(option == $scope.options[index]){ $scope.optionIndex = index; } }) $scope.options[$scope.optionIndex].ifShowCity = false; } $scope.choseProvince = function(target,option){ $.each($scope.options,function(index,item){ if(option == $scope.options[index]){ $scope.optionIndex = index; } }) $scope.options[$scope.optionIndex].ifShowProvince = false; $scope.options[$scope.optionIndex].province = target.getAttribute("data-name"); $.each($scope.province,function(index,item){ if(item.value == target.getAttribute("value")){ $scope.options[$scope.optionIndex].cities = item.children; } } ) } $scope.choseCity = function(target,option){ $.each($scope.options,function(index,item){ if(option == $scope.options[index]){ $scope.optionIndex = index; } }) $scope.options[$scope.optionIndex].ifShowCity = false; $scope.options[$scope.optionIndex].city = target.getAttribute("data-name"); } function getPrarms(){ return $scope.options; } $scope.sub = function(){ getPrarms(); } $scope.province = [{ name: "湖北省", value: "01", children: [{ name: "武汉", value: "0101" }, { name: "黄冈", value: "0102" }, { name: "荆州", value: "0103" }, { name: "十堰", value: "0104" }, { name: "黄石", value: "0105" }, { name: "鄂州", value: "0106" }, { name: "咸宁市", value: "0107" }, { name: "襄阳市", value: "0108" } ] },{ name: "广东省", value: "02", children: [{ name: "广东", value: "0201" }, { name: "深圳", value: "0202" }, { name: "佛山", value: "0203" }, { name: "惠州", value: "0204" }, { name: "东莞", value: "0205" }] },{ name: "河北省", value: "03", children: [{ name: "北京", value: "0301" }, { name: "邯郸", value: "0302" }, { name: "邢台", value: "0303" }, { name: "保定", value: "0304" }, { name: "秦皇岛", value: "0305" } ]} ] $scope.choseP = function($index){ $scope.options[$index].ifShowProvince = !$scope.options[$index].ifShowProvince; $scope.options[$index].ifShowCity = false; } $scope.choseC = function($index){ $scope.options[$index].ifShowCity = !$scope.options[$index].ifShowCity; $scope.options[$index].ifShowProvince = false; } $scope.addChose = function($index){ if($scope.options.length < 10){ $scope.options.splice($scope.options.length,0,{ //从最后面添加内容 index:$scope.options.length,ifShowCity:false,ifShowProvince:false }); $scope.canDelete = true; }else{ $scope.canAdd = false; } } $scope.deleteChose = function($index){ if($scope.options.length >1){ $scope.options.splice($index,1); //从当前行删除。 } if($index == 1){ $scope.canDelete = false; } } }); </script> </html>
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
Fixed table header makes the form scroll horizontally
Bootstrap drop-down plug-in dropdown usage tips
The above is the detailed content of Angularjs has secondary linkage with add and delete options. For more information, please follow other related articles on the PHP Chinese website!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Friends who use IE browser will definitely use Internet options to set it up, but they can’t be found on edge browser, so how to open it? In fact, you only need to open the IE browser in the edge browser to set it up. Where are the internet options of the edge browser: 1. Enter the edge browser and click the three dots in the upper right corner. 2. Select "More Tools" in the taskbar. 3. Select "Open with Internet Explorer" in the new interface. 4. Click "Gear Settings" in the upper right corner of the new browser. 5. You can find "Internet Options" in the taskbar. 6. Click to enter settings.

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

By default, macOSSonoma hides all active windows when you click on your desktop wallpaper. This is convenient if you tend to have a bunch of files on your desktop that you need to access. However, if you find this behavior maddening, there is a way to turn it off. Apple's latest macOS Sonoma Mac operating system has a new option called "Click the wallpaper to show the desktop." Enabled by default, this option can be particularly useful if you tend to have multiple windows open and want to access files or folders on your desktop without having to minimize or move the windows. When you enable the feature and click on the desktop wallpaper, all open windows are temporarily swept aside, allowing direct access to the desktop. Once done, you can again

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest
