我是新的angularJs,尝试点击按钮/元素进行一些dom修改。首先,我只是想知道如何通过角度获得以下小提琴链接中的输出。谁能请你帮忙。
$("#clickMe").on("click",function()
{
alert("hi there");
});
提前致谢。
答案 0 :(得分:1)
HTML:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myapp">
<div ng-controller="MyController">
<div ng-click="clickMe()">Click here and see what happens</div>
</div>
</body>
脚本:
angular.module('myapp', [])
.controller('MyController', function($scope) {
$scope.clickMe= function(){
alert("hi there");
}
});
答案 1 :(得分:0)
HTML:
<div ng-app="myapp" ng-controller="myctrl">
<button ng-click="alertme()">click me</button>
</div>
脚本:
var myapp = angular.module('myapp',[])
.controller('myctrl',function($scope){
$scope.alertme = function(){
alert('hi there');
}
});