繁体   English   中英

动态生成jQuery工具提示不显示

[英]Generate jQuery Tooltip dynamically not showing

想法是创建图像列表,每个图像都有一个自定义工具提示,其中包含较大的图像。 这是一个部分“起作用”的示例(工具提示出现在悬停上,但添加了128px的图像,为什么?

http://jsfiddle.net/xpvt214o/157904/

 for(idx = 0; idx < 2; idx++){ var tmpImg = $('<img>') .attr('src', 'https://www.seoclerk.com/pics/551103-1TOqFD1502285018.jpg') .attr('id', idx) .attr('title', '') .width('32px') .height('32px'); var tmpDivCard = $('<div>') .css('position', 'absolute') .css('left', 40*idx) .css('top', 50) .css('zIndex', '1') .append(tmpImg); tmpImg.tooltip({ content: '<img src="https://www.seoclerk.com/pics/551103-1TOqFD1502285018.jpg" style="width:128px;height:128px;"/>' }); $('#map_area').append(tmpDivCard); } 
 <script src="https://code.jquery.com/jquery-3.3.1.js"></script> <script src="https://code.jquery.com/ui/jquery-ui-git.js"></script> <div style=""> <div id="map_area"> </div> </div> 

我的问题是,尽管有图像,但以下代码根本不显示工具提示。

document.addEventListener('DOMContentLoaded', setProfileCards);

function setProfileCards() {
    //debugger;
    var profileCards = (@Html.Raw(Session["profileCards"] as string));
    profileCards.forEach(function (profileCard) {
        var areaName = profileCard.Place.replace(/\./g, '');
        var _elementArea = $("area[id='" + areaName + "']");
        var _elementHTML = $("area[id='" + areaName + "']")[0];

        if (profileCard.Place.startsWith('3.1')) {
            //
            var tmpImg = $('<img title="">')
                .addClass('rounded-circle')
                .attr('src', profileCard.ProfilePic)
                //.attr('id', areaName)
                //.attr('alt', '')
                //.attr('title', profileCard.Name)
                .attr('title', '')
                .width('32px')
                .height('32px');
            tmpImg.click(function (e) {
                _elementArea.trigger('click');
            });

            var left = (parseInt(_elementHTML.coords.split(',')[2]) + parseInt(_elementHTML.coords.split(',')[0])) / 2;
            var top = (parseInt(_elementHTML.coords.split(',')[3]) + parseInt(_elementHTML.coords.split(',')[1])) / 2;
            var tmpDivCard = $('<div>')
                    .css('position', 'absolute')
                    .css('left', left)
                    .css('top', parseInt(_elementHTML.coords.split(',')[3]))
                    .css('zIndex', '1')
                .append(tmpImg);
            tmpImg.tooltip({ content: '<img src="' + profileCard.ProfilePic + '" style="width:128px;height:128px;"/>' });
            $('#map_area').append(tmpDivCard);
        }
    });
}

主要的问题是。 您需要包括jquery-ui的css

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css" />

我看到您为图片style="width:128px;height:128px;"设置了样式style="width:128px;height:128px;"

参见小提琴http://jsfiddle.net/xpvt214o/158120/

暂无
暂无

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

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