如何在使用特定計數動態創建元素後禁用按鈕。我的意思是說,我想點擊一個按鈕創建5 div的動態後禁用按鈕....這是可能的角JS動態創建元素後禁用按鈕
我給小提琴enter code here
HTML的URL
<div ng-app="myApp" ng-controller="customersCtrl">
<button ng-click="createElement()" id="btnCreateElement"ng-disabled="isDisabled">ClickToAdd</button>
<div id="target">
</div>
<button ng-click="toogleElement()">ClickToAdd</button>
<div class="tryIt" ng-if="showDiv"></div>
<div class="tryIt" id="redDiv" ng-if="!showDiv"></div>
JS
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope) {
$scope.showDiv=true;
$scope.isDisabled =false;
$scope.createElement =function(){
var newDiv = angular.element('<div class="test"></div>');
var newDivContainer = document.getElementById("target");
angular.element(newDivContainer).append(newDiv);
$scope.isDisabled =true;
}
$scope.toogleElement=function(){
$scope.showDiv =!$scope.showDiv;
}
});
CSS
.test{width:400px;height:30px;background:green;margin:10px 0;}
.tryIt{width:200px;height:200px;background:#00B3E3;margin-left:50%; position:relative;}
#target>div:nth-child(5){background:blue;}
#redDiv{background:red;}
#btnCreateElement{cursor:pointer;}
#btnCreateElement:disabled{cursor:no-drop;}
https://jsfiddle.net/e61rdhtb/1/
嘗試添加計數器對創建的div –
,你可以請更新FIDDLE @賈揚特·PATIL –