繁体   English   中英

从页面获取特定内容以通过Ajax插入Bootstrap 3模式

[英]Getting specific content from page to be inserted to bootstrap 3 modal via ajax

我试图通过ajax将页面中的特定内容拉入bootstrap 3模态,但只能拉入整个页面。

这是我的jQuery代码:

function wineMap() {

    var wh = $(window).height();
    var hh = $('#masthead').height();
    $('.wine-menu #mainstage').css({
        height: wh-hh-80
    });
    $('#wine-map').vectorMap({
        map: 'world_en',
        backgroundColor: '#000',
        color: '#ffffff',
        hoverOpacity: 0.7,
        selectedColor: '#666666',
        enableZoom: true,
        scaleColors: ['#ffffff', '#eeeeee'],
        normalizeFunction: 'polynomial',
        onRegionClick: function(element, code, region){
            if (code == 'us')    {
                var url = 'http://cb.dannycheeseman.me/wine-menu/'+code;
            }
            $('#theModal').modal({
                show : true,
                remote: url
            });
        }
    });
}

$(document).ready(function(e) {
    wineMap();
});

这是网址http://cb.dannycheeseman.me/wine-menu/ (点击美国)

我努力了:

function wineMap() {

    var wh = $(window).height();
    var hh = $('#masthead').height();
    $('.wine-menu #mainstage').css({
        height: wh-hh-80
    });
    $('#wine-map').vectorMap({
        map: 'world_en',
        backgroundColor: '#000',
        color: '#ffffff',
        hoverOpacity: 0.7,
        selectedColor: '#666666',
        enableZoom: true,
        scaleColors: ['#ffffff', '#eeeeee'],
        normalizeFunction: 'polynomial',
        onRegionClick: function(element, code, region){
            if (code == 'us')    {
                var url = 'http://cb.dannycheeseman.me/wine-menu/'+code;
            }
            $('#theModal').modal({
                show : true,
                remote: url+'#menu-home-location'
            });
        }
    });
}

$(document).ready(function(e) {
    wineMap();
});

注意:

                remote: url+'#menu-home-location'

我希望可以仅提取该id的内容,但仍会提取整个页面。

问候

好的,因此,在阅读了jQuery load函数之后,我意识到您想要添加的内容的ID之前需要一个空格,因此:

            $('#theModal').modal({
                show : true,
                remote: url+'#menu-home-location'
            });

成为:

            $('#theModal').modal({
                show : true,
                remote: url+' #menu-home-location'
            });

而且效果很好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM