模态中的数据关闭在单击时被调用两次
Data dismiss in modal being called twice on click
我一直在工作一种模式,当用户单击"取消"按钮时,该模式会被关闭。一切都工作正常,直到按钮出现错误。当我单击"取消"按钮时,模态被关闭,但关闭并再次打开。因此,需要单击关闭按钮两次才能关闭模态。
这是"引导"模式,我没有对JS文件进行任何更改。只有CSS和HTML被修改过。在浏览器中检查时,我看到以下函数被调用了两次。
<div class="modal-backdrop fade in"></div>
如何修复此错误?我什至不知道从哪里开始!以下是我的模态代码。
注意:模态右上角的"交叉"咏叹调标签也遇到了同样的错误。
<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<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="myModalLabel"><b>Why are you deleting this book?</b></h4>
</div>
<!--modal body starts -->
<div class="modal-body">
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>Sold
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">Sold on another site or elsewhere
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">Don't want to sell it now
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">Lack of buyer interest
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">Vacation, break
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">Other reason
</label>
</div>
</div>
<!--modal body end -->
<div class="modal-footer">
<button type="button" class="btn btn-primary">Delete</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
打开模式的按钮的 HTML 代码
<button type= "submit" class="dashbtn dashbtn-danger">EDIT</button><br>
<button type= "button" class="dashbtn dashbtn-primary" data-toggle="modal" data-target=".bs-example-modal-sm">DELETE</button>
当代码中有多个模式共享同一类时,通常会发生这种情况。为防止出现此类情况,请为模态分配不同的 ID,并在数据目标属性中使用该 ID。试试这个:
<button type="submit" class="dashbtn dashbtn-danger">EDIT</button>
<br>
<button type="button" class="dashbtn dashbtn-primary" data-toggle="modal" data-target="#bs-example-modal-sm">DELETE</button>
对于您的模态:
<div class="modal fade" id="bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<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="myModalLabel"><b>Why are you deleting this book?</b></h4>
</div>
<!--modal body starts -->
<div class="modal-body">
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>Sold
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">Sold on another site or elsewhere
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">Don't want to sell it now
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">Lack of buyer interest
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">Vacation, break
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">Other reason
</label>
</div>
</div>
<!--modal body end -->
<div class="modal-footer">
<button type="button" class="btn btn-primary">Delete</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
只需确保为每个模态分配不同的 ID,并使用 data-target="#foo"
触发每个
查找有关模态数据属性的部分:引导模态
相关文章:
- Meteor Router数据函数被调用两次
- Backbone.js ListenToOnce被调用两次
- 为什么DTM数据元素被调用两次
- 模态中的数据关闭在单击时被调用两次
- java-script 函数被调用两次
- rails4-javascript文件需要调用两次才能工作
- javascript点击被调用两次甚至两次以上
- 回调函数在引导模态上调用两次甚至更多次
- 具有超时的地理位置会导致错误处理程序被调用两次
- 如何在同一元素中调用两次onclick
- 调用两次时间更新
- 聚合物元素注册和生命周期(创建和准备调用两次)
- AngularJS自定义过滤器被调用两次
- 为什么 console.log() 被调用两次而不是一次
- Phonegap PushPlugin 消息事件被调用两次
- jquery 使用承诺调用两次动画完成
- .is(“:animated”) 选择器在动画期间返回 true,并调用两次
- 调用两次时 jQuery 偏移量(坐标)的行为不一致
- 为什么单击处理程序被调用两次
- $(document).ready(function(){} jquery被调用两次