引导模式在单击时打开并保持打开状态 10 秒
Bootstrap modal open on click and stays open for 10 sec
我想在单击时打开模态,在模态中我有表单和提交按钮。当用户填写表单时,我想显示消息,如果提交为真或伪造,并在 10 秒后自动关闭模式。
这是我现在的代码,一切正常,但即使我不点击按钮,我的模态也会打开。
网页代码:
<a href="#insert_poslovni" class="btn btn-default btn-sm" data-toggle="modal" id="insert_p">Unos</a>
JS代码:
<script>
$(function(){
//instantiate your content as modal
$("#insert_poslovni").modal({
//modal options here, like keyboard: false for e.g.
});
setTimeout(function() {$("#insert_poslovni").modal("hide");}, 10000);;
//show the modal when dom is ready
$("#insert_poslovni").modal("show");
});
</script>
这样的东西? http://jsfiddle.net/swm53ran/148/
$(document).ready(function() {
$('.open').on('click', function() {
$('#myModal').modal('show');
});
$('.submit').on('click', function (e) {
e.preventDefault();
setTimeout(function() {
$('#myModal').modal('hide');
}, 10000);
});
});
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg open">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<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">Modal title</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary submit">Submit</button>
</div>
</div>
</div>
</div>
更改为:
$(function(){
$("#insert_poslovni").modal({ //modal options });
$("#submitbuttonid").on('click', function(e){
setTimeout(function() {$("#insert_poslovni").modal("hide");}, 10000);
e.preventDefault();
});
});
这仅在单击按钮后启动代码您还可以通过设置和ID将相同的功能添加到关闭按钮
http://jsfiddle.net/ge0g8kbc/25/
使用你的js Fiddle,这里是更新的工作版本:http://jsfiddle.net/pzaLqxL2/2/
e.preventDefault()
为小写"p"
$(function(){
$("#insert_p").click(function(){
// rest of code in here
$("#insert_poslovni").on("hide.bs.modal", function(e){
if($("#insert_poslovni").data("prevented") !== "prevented"){
$("#insert_poslovni").data("prevented", "prevented");
e.preventDefault();
setTimeout(function() {$("#insert_poslovni").modal("hide");}, 10000);
}
else{
$("#insert_poslovni").data("prevented", "");
}
});
});
});
相关文章:
- 即使我单击“确定”,模型弹出窗口扩展器仍保持打开状态
- 单击我网站中的链接时打开新选项卡,保持当前选项卡处于活动状态
- 在单击按钮时激活按钮的悬停状态,直到单击另一个按钮(Javascript/JQuery)
- 重置按钮在 jQuery 中的单击状态
- 当单击<a>链接在chrome扩展中,popup.html如何保持打开状态
- 创建一个复选框按钮的散列,这些按钮在单击时在Twitter Bootstrap Button组中处于活动状态
- 悬停样式应该在动态加载多级菜单时保持单击状态
- 如何在第一次点击时突出显示链接;并在第二次单击时跟随它,除非在其他地方单击,然后重新初始化未高亮显示的状态
- 在AngularJS中切换编辑状态并更改项目'单击另一个函数
- 如何通过在javascript中单击浏览器的后退按钮将页面恢复到以前的状态
- Ajax通过单击javascript按钮更改php状态
- 单击按钮更改组件状态
- 引导模式在单击时打开并保持打开状态 10 秒
- Jquery:更改选择框值并激活单击状态
- 单击关闭时,使引导下拉列表保持打开状态
- 在两个或多个 UL 列表之间切换,如果单击一个列表,则其他列表会自动以初始状态返回,就像从未单击过一样
- 使容器保持打开状态,以便首次单击每个导航项
- 多个按钮,每个按钮都有不同的样式 - 单击后需要保持悬停状态
- 是否可以在不导致单击事件的情况下更改复选框状态
- reactJS在转到另一个URL时如何传递状态?(单击导航栏上的“新建”,转到提交表单)