利用angularjs实现,点击一个div区域会将该div的背景颜色传给另一个div,从而改变其背景颜色
1个回答
展开全部
JS代码:
!function (global) {
var mod = angular.module('test.bg', []);
mod.controller('bgController', ['$scope', function ($scope) {
$scope.div1Bg = '#ffffff';
$scope.div2Bg = '#ffffff';
$scope.changeBg = function () {
$scope.div2Bg = $scope.div1Bg;
};
}]);
}(this);
HTML代码:
<body ng-controller="bgController">
<div style="background-color: {{div1Bg}}" ng-click="changeBg()">div1</div>
<div style="background-color: {{div2Bg}}">div2</div>
</body>
!function (global) {
var mod = angular.module('test.bg', []);
mod.controller('bgController', ['$scope', function ($scope) {
$scope.div1Bg = '#ffffff';
$scope.div2Bg = '#ffffff';
$scope.changeBg = function () {
$scope.div2Bg = $scope.div1Bg;
};
}]);
}(this);
HTML代码:
<body ng-controller="bgController">
<div style="background-color: {{div1Bg}}" ng-click="changeBg()">div1</div>
<div style="background-color: {{div2Bg}}">div2</div>
</body>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询