0

在我正在处理的网站的主页上,我想要一张实际地点的照片,上面有一个名为“查看更多”的按钮

单击该按钮时,会将用户转移到另一个页面,在那里他可以找到一个 openlayers 地图,该地图上已经呈现了该地点的空间点。

现在,为了实现这一点,我需要将地点的名称从主页转移到地图页面,当单击按钮并立即调用 javascript 函数,以便让 openlayers 在地图上呈现点

我该怎么做呢?

传输数据并立即调用 javascript 函数?

提前致谢

4

1 回答 1

2

The classic way to do this would be to add a query parameter to the galleries page URL before you open it like this:

/galleries?placeID=3456

Then, you can access that placeID either on the server or in the galleries page javascript (whichever you want).


In the galleries page, you would then have some javascript that runs when the page is initialized. That javascript would examine the query parameters on the URL and act accordingly.

$(document).ready(function() {
    // examine window.location.search here to look at the query parameters
    var matches = window.location.search.match(/placeID=(.*?)(&|$)/);
    if (matches) {
        var placeID = matches[1];
        // do whatever you want with placeID here
    }
});
于 2013-10-21T00:39:52.407 回答