【问题标题】:Calling thickbox from a js file从 js 文件调用thickbox
【发布时间】:2009-04-19 09:47:06
【问题描述】:

您好,我正在尝试将粗框添加到 googlemaps 中的叠加层。在我的 JQuery onload 函数中,我调用了以下函数。地图工作正常。但是当厚框似乎没有被调用时。这是行之有效的行

<a href="test.html?keepThis=true&TB_iframe=true&height=250&width=400" title="add a caption to title attribute / or leave blank" class="thickbox">Example 1</a>

整个函数

function load(lat, lng, zlevel, userKey, state) {

        map = new GMap2(document.getElementById("map"));
        map.disableDoubleClickZoom();
        map.setCenter(new GLatLng(lat, lng), zlevel);

        if (state) {

            dsp = true;

            map.addControl(new GLargeMapControl());
            GEvent.addListener(map, "click", function(overlay, latlng) {

                var zoom = map.getZoom();
                var display = '<h5 class="header-flag">Flag</h5><p class="maptext"><a href="#" onclick="javascript:openOverlay(' + latlng.lat() + ',' + latlng.lng() + ',' + zoom + ');">Click here</a> to enter your comment - 
<a href="test.html?keepThis=true&TB_iframe=true&height=250&width=400" title="add a caption to title attribute / or leave blank" class="thickbox">Example 1</a></p>';

                setTimeout(function() { map.openInfoWindowHtml(latlng, display, { maxWidth: 200 }); }, 0);
            });
        } else {


        }

        mgr = new MarkerManager(map);
        loadMarkers(userKey);
        mgr.refresh();
    }

【问题讨论】:

  • 请说明您的示例源代码
  • 所以,我的帖子有点乱。我已经更新了:)

标签: jquery thickbox


【解决方案1】:

在调用thickbox 函数后,您将要激活thickbox 的链接添加到DOM。这是因为您正在 map.openInfoWindowHtml 函数中动态创建链接。该函数执行完毕后需要调用thickbox函数。

问题是我刚刚查看了thickbox 文档,并且一旦DOM 加载,thickbox 就会在thickbox.js 文件中设置,这对您来说太早了。您可以尝试将 setTimeout 函数更改为:

setTimeout(function() { map.openInfoWindowHtml(latlng, display, { maxWidth: 200 }); tb_init('a.thickbox'); }, 0);

我不能 100% 确定这会奏效,但这是问题的症结所在。

【讨论】:

  • 你是绝对正确的。新创建的厚盒元素需要使用 tb_init 函数进行初始化。除非他/她的代码中存在其他问题,否则这没有理由不工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-14
  • 2015-09-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多