AngularJs,Img,onclick

时间:2015-11-12 12:37:21

标签: javascript jquery html angularjs

我必须做一个网站。在此网站上,当您单击img时,它会向div添加一个文本。 它必须有指令和控制器,我不知道如何做到这一点......

<!DOCTYPE HTML>
<html>
<head>
<script src="http://code.angularjs.org/1.2.7/angular.min.js"></script>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel="Stylesheet" type="text/css" href="styles/style.css">
<title>AngularJS System Zamówień</title>
<script>
var myApp = angular.module('myApp', []);
myApp.controller('myCtrl', function($scope) {
    $scope.data = new Date();
    $scope.hambureger ={
        nazwa: 'Hambureger',
        cena: '5',
    }
    $scope.crips = {
        nazwa: 'Crips',
        cena: '4',
    }
    $scope.cola = {
        nazwa: 'Coca-Cola',
        cena: '3',
    }
    $scope.show = function() {

   }
   }
   myApp.directive1('myDir1', function () {
  return {
        restrict: 'A',
        template: '<br>{{hamburger.nazwa}}'

    };
});
myApp.directive2('myDir2', function () {
  return {
        restrict: 'A',
        template: '<br>{{frytki.nazwa}}
    };
});
myApp.directive3('myDir3', function () {
  return {
        restrict: 'A',
        template: '<br>{{cola.nazwa}}'

    };
});
});

</script>
</head>
<body>
<h1 class="ladne"><center>System zamówień żarcia</center></h1>
<div class="d1" ng-app="myApp" ng-controller="myCtrl">
<img src="styles/img/cola.gif" ng-click=""></img>
<img src="styles/img/fryt.gif" ng-click=""></img>
<img src="styles/img/ham.gif" ng-click=""></img>
<br>
<div class="zam">
Data Zamówienia: {{data |date:'yyyy-MM-dd'}}
<br>
Twoje zamówienie: //HERE ANGULAR MUST ADD A TEXT
</div>
</div>
</body>
</html>

这对我来说真的很难...... 那么让我们再说一遍: 当你点击img时,文本被添加到div(class =“zam”),当你按下img时它会在新行中添加新文本。这里有3个不同的imgs Crips,Hambureger'n'cola

0 个答案:

没有答案