Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 是否有一种方法可以在新选项卡打开之前先打开引导模式?_Jquery_Twitter Bootstrap - Fatal编程技术网

Jquery 是否有一种方法可以在新选项卡打开之前先打开引导模式?

Jquery 是否有一种方法可以在新选项卡打开之前先打开引导模式?,jquery,twitter-bootstrap,Jquery,Twitter Bootstrap,下面的代码将在引导模式出现之前首先打开新选项卡。有没有办法在新选项卡之前先打开引导模式 $(document).on("click", ".listings", function() { var id = $(this).attr("id"); $.ajax({ url: "http://api.myjson.com/bins/2sadq?pretty=1", dataType: "json", success: funct

下面的代码将在引导模式出现之前首先打开新选项卡。有没有办法在新选项卡之前先打开引导模式

$(document).on("click", ".listings", function() {
     var id =  $(this).attr("id");

     $.ajax({
        url: "http://api.myjson.com/bins/2sadq?pretty=1",
        dataType: "json",
        success: function(response) {

            var modal = "<div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel'><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'>&times;</span></button><h4 class='modal-title' id='myModalLabel'>Aloha!</h4></div><div class='modal-body'>Apartment address through Google Maps. Epic! Right?</div><div class='modal-footer'><button type='button' class='btn btn-default' data-dismiss='modal'>Close</button></div></div></div></div>";
            $('#myModal').modal('show');
            $(".modals").append(modal);

            var selectedApartment = $.grep(response.apartments, function(apartment) {
                return apartment.id == id;
            });

            var address = selectedApartment[0].address;

            window.open("http://maps.google.com/?q=" + address);
        },

        error: function(error) {
            console.log(error);
        }

    });
});
$(document).on(“单击“,”.listings”,函数(){
var id=$(this.attr(“id”);
$.ajax({
url:“http://api.myjson.com/bins/2sadq?pretty=1",
数据类型:“json”,
成功:功能(响应){
var modal=“×;Aloha!通过谷歌地图的公寓地址。Epic!右?关闭”;
$('myModal').modal('show');
$(“.modals”).append(模态);
var selectedpartment=$.grep(response.partments,function(partment){
return repartment.id==id;
});
var address=selectedpartment[0]。地址;
窗口打开(“http://maps.google.com/?q=“+地址);
},
错误:函数(错误){
console.log(错误);
}
});
});
另外,如果您想查看完整的项目文件,这里有dropbox链接


您还可以设置超时来延迟打开的弹出窗口:

setTimeout(function() {window.open("http://maps.google.com/?q=" + address)}, 1000);
更新:如果您想在单击关闭按钮后显示弹出窗口:

success: function(response) {

                var modal = "<div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel'><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'>&times;</span></button><h4 class='modal-title' id='myModalLabel'>Aloha!</h4></div><div class='modal-body'>Apartment address through Google Maps. Epic! Right?</div><div class='modal-footer'><button type='button' class='btn btn-default' data-dismiss='modal'>Close</button></div></div></div></div>";

                $(".modals").html(modal);

                var selectedApartment = $.grep(response.apartments, function(apartment) {
                    return apartment.id == id;
                });

                var address = selectedApartment[0].address;

                $('#myModal').on('hide.bs.modal', function (e) {
                    window.open("http://maps.google.com/?q=" + address);
                });
                $('#myModal').modal('show');
            },
成功:功能(响应){
var modal=“×;Aloha!通过谷歌地图的公寓地址。Epic!右?关闭”;
$(“.modals”).html(模态);
var selectedpartment=$.grep(response.partments,function(partment){
return repartment.id==id;
});
var address=selectedpartment[0]。地址;
$('#myModal').on('hide.bs.modal',函数(e){
窗口打开(“http://maps.google.com/?q=“+地址);
});
$('myModal').modal('show');
},

这很有效。我只是想知道,是否只有当我点击模式上的“关闭”按钮时,新选项卡才会打开?我只是注意到模式在第一次呼叫或单击时无法工作。为什么?哇,现在太完美了!为什么使用.html()而不是.append()方法?哪种代码修复第一次呼叫时模式不工作?1。使用append()时,会添加许多模态,因此会有许多重复模态。2.您必须在$(“.modals”).html(modal)之后调用$(“.myModal”).modal('show'),因为modal现在是DOM中的真正元素。在您的代码中,在模态显示成为真正的元素之前,您已经调用了它。明白了。关于如何提高我对bootstrap和jquery等第三方文档的理解,您有什么建议吗?