javascript-控制引导程序确认模式中的确认按钮
作者:互联网
我将示例更改为一个简单的示例.当我单击“删除此{{item.id}}”按钮时,我想调用删除功能.标题成功获取了item.id值.
<h4 class="modal-title" id="exampleModalLabel">Do you want to remove {{item.id}}</h4>
但是该按钮未获得item.id值,并且该功能无法正常工作.而不是“ Remove this item.id”,而仅仅是“ Remove this”,该函数也无法获取参数.
<button type="button" id="exampleModalLabel" class="btn btn-primary" ng-click="removeItem(item.id)">Remove this {{item.id}}</button>
我所拥有的是:
<tr ng-repeat="item in items">
<td>{{item.id}}</td>
<td><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="{{item.id}}">Remove this item?</button></td>
</tr>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="exampleModalLabel">Do you want to remove {{item.id}}</h4>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" ng-click="removeItem(item)">Remove this {{item.id}}</button>
</div>
</div>
</div>
</div>
//And this javascript
$('#exampleModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget);
var recipient = button.data('whatever');
var modal = $(this);
modal.find('.modal-title').text('New message to ' + recipient);
modal.find('.modal-body input').val(recipient);
});
我希望信息足够.如果您需要更多信息,请告诉我.
解决方法:
尝试使用此:
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" id="removeButton" class="btn btn-primary">Remove this <span id="itemid"></span></button>
</div>
//JS
$('#exampleModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget);
var recipient = button.data('whatever');
var modal = $(this);
modal.find('.modal-title').text('New message to ' + recipient);
modal.find('.modal-body input').val(recipient);
modal.find('#itemid').html(recipient); // add this
modal.find('#removeButton').attr('ng-click', 'removeItem('+recipient+')'); // add this
});
标签:bootstrap-modal,angularjs,twitter-bootstrap,javascript,jquery 来源: https://codeday.me/bug/20191027/1944785.html