angular,添加,删除元素,动态

HTML: 

<div ng-repeat="p in postBack" style="overflow: hidden;">
    <div class="form-group" style="width: 47.5%;float: left;">
        <input type="text" class="form-control" name="firstName{{$index}}"/>
    </div>
    <div class="form-group"  style="width: 47.5%;float: left;margin-bottom: 0px">
        <input type="text" class="form-control"  name="lastName{{$index}}" />
    </div>
    <button style="top: 36px;right: 0px;color: #9960a7;opacity: inherit;position: relative;" type="button" ng-click="addGuestName(postBack.length)" ng-show="$index==0">+</button>
    <button style="top: 35px;right: 0px;color: #9960a7;opacity: inherit;position: relative;" type="button" ng-click="deleteGuestName($index)" ng-show="$index!=0">×</button>
</div>

JS:

$scope.postBack = [{}];
$scope.addGuestName = function(idx){
    var postBack={};
    $scope.postBack.push(postBack);

};
$scope.deleteGuestName = function(idx){
    $scope.postBack.splice(idx,1);
};

就OK啦。就利用ng-repeat数组。谢谢

可以参考https://blog.csdn.net/weixin_36185028/article/details/72866963

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值