Javascript 在引导确认模式中控制确认按钮
我把这个例子改成了一个简单的例子。当我点击“删除这个{{item.id}}”按钮时,我想调用一个delete函数。标题已成功获取item.id值Javascript 在引导确认模式中控制确认按钮,javascript,jquery,angularjs,twitter-bootstrap,bootstrap-modal,Javascript,Jquery,Angularjs,Twitter Bootstrap,Bootstrap Modal,我把这个例子改成了一个简单的例子。当我点击“删除这个{{item.id}}”按钮时,我想调用一个delete函数。标题已成功获取item.id值 <h4 class="modal-title" id="exampleModalLabel">Do you want to remove {{item.id}}</h4> 是否要删除{{item.id} 但是按钮没有获得item.id值,函数也不起作用。而不是“Remove this item.id”,它只是“Remove
<h4 class="modal-title" id="exampleModalLabel">Do you want to remove {{item.id}}</h4>
是否要删除{{item.id}
但是按钮没有获得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>
删除此{{item.id}
我所拥有的是:
<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);
});
{{item.id}
是否删除此项目?
&时代;
是否要删除{{item.id}
接近
删除此{{item.id}
//这个javascript
$('exampleModal').on('show.bs.modal',函数(事件){
var按钮=$(event.relatedTarget);
var recipient=button.data('whatever');
var modal=$(本);
modal.find('.modal title').text('发送给'+收件人的新邮件');
modal.find('.modal body input').val(收件人);
});
我希望这些信息足够了。如果您需要更多信息,请告诉我。您的模式超出了
项目的范围。您需要将项分配给控制器内的某个温度变量。您应该使用ng click
来实现这一点,类似于ng click=“tempItem=item”
。您可能还必须编辑removietem
函数
<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}}" ng-click="tempItem = item">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 {{tempItem.id}}</h4>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" id="exampleModalLabel" class="btn btn-primary" ng-click="removeItem(tempItem)">Remove this {{tempItem.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);
});
{{item.id}
是否删除此项目?
&时代;
是否要删除{{tempItem.id}
接近
删除此{{tempItem.id}
//这个javascript
$('exampleModal').on('show.bs.modal',函数(事件){
var按钮=$(event.relatedTarget);
var recipient=button.data('whatever');
var modal=$(本);
modal.find('.modal title').text('发送给'+收件人的新邮件');
modal.find('.modal body input').val(收件人);
});
尝试使用以下方法:
<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
});
接近
去掉这个
//JS
$('exampleModal').on('show.bs.modal',函数(事件){
var按钮=$(event.relatedTarget);
var recipient=button.data('whatever');
var modal=$(本);
modal.find('.modal title').text('发送给'+收件人的新邮件');
modal.find('.modal body input').val(收件人);
modal.find('#itemid').html(收件人);//添加此
modal.find('#removeButton').attr('ng-click','removietem('+recipient+'));//添加此
});
removeItem(item.id)不应该是removeItem({{item.id}})吗?不,相同的结果。。。它甚至不能在innerHTML上显示…模式是否出现在屏幕上?您可以通过javascript设置值来解决问题。在JS:var item={{item.id}}中设置值;然后在函数中为modal:modal.find('.modal body button').attr(“ng click”,“removietem”(+item+)))@Paulmordan我试过了,但它仍然不起作用…即使modal没有项目,它仍然能够在中获取item.id
是否要删除{{item.id}
为什么它在中无法获取它删除这个{item.id}
我认为它无法在h4
中获取item.id
,您只需使用jquerymodal.find('.modal title').text('发送给'+收件人的新邮件')更改h4
内容事实上是的,我的错!看起来一切正常,但函数不想触发。。。我不知道为什么。。。我正在试着调试它,看看出了什么问题,但它似乎只是没有触发功能…一个为工程罚款。。。它甚至还添加了“ng click=”removietem(myItem)”,但当我单击时,该函数不会触发…很抱歉听到这个消息。不幸的是,我不知道AngularJs,我无法在这方面为您提供帮助。以下链接可能会有所帮助: