Home Web Front-end JS Tutorial Example of provincial and municipal secondary linkage functions implemented by AngularJS

Example of provincial and municipal secondary linkage functions implemented by AngularJS

Jan 02, 2018 pm 03:58 PM
angularjs javascript Linkage

This article mainly introduces the provincial and municipal secondary linkage functions implemented by AngularJS, which involves event monitoring, response and dynamic operation of page elements. In addition, it also has the function of adding and deleting options. Friends who need it can refer to it. I hope it can help. to everyone.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

<!DOCTYPE html>

<html>

<head>

 <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 ng-repeat = "option in options">

<p>

 <dl>

  <dd ng-click="choseP($index)" ng-value="false">{{option.province}}</dd>

  <dt 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>

 <dl>

  <dd ng-click="choseC($index)" ng-value="false">{{option.city}}</dd>

  <dt 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 ng-click="addChose($index)">+</span>

 <span 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>

Copy after login

Related recommendations:

jquery’s ajax implementation method to achieve the secondary linkage effect

Realize the registration page jq secondary level Linkage

How to achieve select select secondary linkage effect

The above is the detailed content of Example of provincial and municipal secondary linkage functions implemented by AngularJS. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement an online speech recognition system using WebSocket and JavaScript How to implement an online speech recognition system using WebSocket and JavaScript Dec 17, 2023 pm 02:54 PM

How to implement an online speech recognition system using WebSocket and JavaScript

Zhengtu IPx classic animation 'Journey to the West' The journey to the west is fearless and fearless Zhengtu IPx classic animation 'Journey to the West' The journey to the west is fearless and fearless Jun 10, 2024 pm 06:15 PM

Zhengtu IPx classic animation 'Journey to the West' The journey to the west is fearless and fearless

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems

How to implement an online reservation system using WebSocket and JavaScript How to implement an online reservation system using WebSocket and JavaScript Dec 17, 2023 am 09:39 AM

How to implement an online reservation system using WebSocket and JavaScript

How to use JavaScript and WebSocket to implement a real-time online ordering system How to use JavaScript and WebSocket to implement a real-time online ordering system Dec 17, 2023 pm 12:09 PM

How to use JavaScript and WebSocket to implement a real-time online ordering system

JavaScript and WebSocket: Building an efficient real-time weather forecasting system JavaScript and WebSocket: Building an efficient real-time weather forecasting system Dec 17, 2023 pm 05:13 PM

JavaScript and WebSocket: Building an efficient real-time weather forecasting system

Double chef ecstasy! 'Onmyoji' x 'Hatsune Miku' collaboration starts on March 6 Double chef ecstasy! 'Onmyoji' x 'Hatsune Miku' collaboration starts on March 6 Feb 22, 2024 pm 06:52 PM

Double chef ecstasy! 'Onmyoji' x 'Hatsune Miku' collaboration starts on March 6

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

Simple JavaScript Tutorial: How to Get HTTP Status Code

See all articles