就像这样,我想按下回车之后在html中添加一个元素<p class='main'></p>, if下面该怎么写?还有一个问题,angularjs到底是怎么来操作DOM的,刚开始学,不太理解。
var app = angular.module('myApp',[])
.controller('todoCtrl',function ($scope) {
$scope.enterEvent = function(e) {
var keycode = window.event?e.keyCode:e.which;
if(keycode==13){
}
}
});
Data-driven model.
You need to change your thinking about operating dom.
What do you want to do after entering? You need an extra dom. Assuming that the previous dom number is 0, then if you press Enter, it will be +1.
Then it’s easy. You first define a variable. Whether the variable is initialized to 1 or 10,000 depends on your mood.
You can put this
<p class='main'></p>
先写在页面上,写在todoCtrl
in. Then add the ngShow syntax to the element to control the hiding and display of the element at any time: