您好,登錄后才能下訂單哦!
本文實例講述了AngularJS+bootstrap實現動態選擇商品功能。分享給大家供大家參考,具體如下:
項目中后臺一個商品庫,新建活動時動態選擇所需商品
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="bootstrap.min.css" rel="external nofollow" > <script src="jQuery.min.js"></script> <script src="angular.js"></script> <script src="angular-animate.js"></script> <script src="bootstrap.min.js"></script> <script type="text/JavaScript"> var app = angular.module('myapp', []); app.controller('DemoCtrl', function ($scope) { $scope.promotionProducts = []; $scope.pic = ''; $scope.allPictures = [ { name : '濃縮蕃茄', image : 'http://vincenthou.qiniudn.com/aa0f41e7aa0b24dbe6e20b3f.png', description : '2kg x2罐 每組建議售價: 420', href : 'www.baidu.com' }, { name : '龍蝦汁粉', image : 'http://vincenthou.qiniudn.com/51c37a943a161b2d0b510a48.png', description : '500g x1盒 每組建議售價: 400', href : 'www.baidu.com' }, { name : '美玉白汁', image : 'http://vincenthou.qiniudn.com/eaf6459357ce21a87e586312.png', description : '3.5kg x1盒 每組建議售價: 396', href : 'www.baidu.com' } ]; $scope.addOption = function(content) { if (content == '') { return; } $scope.promotionProducts.push(content); $scope.allPictures.splice($scope.allPictures.indexOf(content), 1); $scope.pic = ''; } $scope.deleteOption = function(item) { $scope.allPictures.push(item); $scope.promotionProducts.splice($scope.promotionProducts.indexOf(item), 1); } }); </script> </head> <body ng-app="myapp"> <div ng-controller="DemoCtrl"> <div> <div> <h2>option</h2> </div> <div> <div> <table class="table table-striped table-bordered table-hover table-condensed"> <thead> <tr> <th>商品名稱</th> <th>商品描述</th> <th>商品鏈接</th> <th>商品圖片</th> <th>操作</th> </tr> </thead> <tbody> <tr ng-repeat="item in promotionProducts"> <td class="col-md-3"><label>{{item.name}}</label></td> <td class="col-md-3"><label>{{item.description}}</label></td> <td class="col-md-3"><label>{{item.href}}</label></td> <td class="col-md-2"><img ng-src="{{item.image}}" /></td> <td class="col-md-1"> <button type="button" class="btn btn-success btn-sm" ng-click="deleteOption(item)">Delete </button> </td> </tr> </tbody> </table> </div> <select ng-options="item.name for item in allPictures" ng-model="pic"> <option value="">選擇商品</option> </select> <a class="btn btn-success btn-xs" ng-click="addOption(pic)">Add</a> </div> </div> </div> </body> </html>
運行效果圖如下:
更多關于AngularJS相關內容感興趣的讀者可查看本站專題:《AngularJS指令操作技巧總結》、《AngularJS入門與進階教程》及《AngularJS MVC架構總結》
希望本文所述對大家AngularJS程序設計有所幫助。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。