簡體   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