侧边栏问题 - HTML 列表的更改
您好,我想知道是否有人可以帮助我,因为我已经陷入了困境,我不知道如何解决这个问题。
我正在使用 此 页面为用户提供能够选择的功能并通过复选框取消选择地图上的标记。然后,他们可以单击地图上或通过左侧边栏的任何标记,从右侧边栏的下拉菜单中选择半径设置,并在给定半径内搜索 POI。
我想做的是更改左侧侧边栏以匹配右侧侧边栏的格式。
我知道需要更改的代码是这样的:
function myclick(i) {
google.maps.event.trigger(gmarkers[i],"click");
}
// == rebuilds the sidebar to match the markers currently displayed ==
function makeSidebar() {
var html = "";
for (var i=0; i<gmarkers.length; i++) {
if (gmarkers[i].getVisible()) {
html += '<a href="javascript:myclick(' + i + ')">' + gmarkers[i].myname + " - " + gmarkers[i].myfinds + " Finds made" + '<\/a><br>';
}
}
document.getElementById("side_bar").innerHTML = html;
}
我尝试将其替换为下面的代码,该代码取自在右侧创建侧边栏的脚本片段。
function createSidebarEntry(marker2, sitedescription, distance) {
var div = document.createElement('div');
var html2 = '<b>' + sitedescription + '</b> (' + distance.toFixed(1) + ' miles) <br/>';
div.innerHTML = html2;
div.style.cursor = 'pointer';
div.style.marginBottom = '5px';
google.maps.event.addDomListener(div, 'click', function() {
google.maps.event.trigger(marker2, 'click');
});
google.maps.event.addDomListener(div, 'mouseover', function() {
div.style.backgroundColor = '#eee';
});
google.maps.event.addDomListener(div, 'mouseout', function() {
div.style.backgroundColor = '#fff';
});
return div;
}
这就是我到目前为止所做的。我可以让标记出现在地图上,但无法渲染左侧的侧边栏。
我已经为此工作好几天了,但我似乎一直在兜圈子。我只是想知道是否有人可以看一下这个并让我知道我哪里出了问题。
非常感谢和亲切的问候
Hi I wonder whether someone could help me please, as I've got myself into a bit of a pickle with this and I'm not sure how to resolve this.
I'm using this page to give the user the functionality of being able to select and deselect markers on the map via check boxes. They can then click on any marker, either on the map, or via the left hand sidebar, select a radius setting from the drop down menu in the right hand sidebar and search for POI's within that given radius.
What I'm trying to do is change the sidebar on the left hand side to match the format of the one on the right.
I know that the piece of code that needs to change is this:
function myclick(i) {
google.maps.event.trigger(gmarkers[i],"click");
}
// == rebuilds the sidebar to match the markers currently displayed ==
function makeSidebar() {
var html = "";
for (var i=0; i<gmarkers.length; i++) {
if (gmarkers[i].getVisible()) {
html += '<a href="javascript:myclick(' + i + ')">' + gmarkers[i].myname + " - " + gmarkers[i].myfinds + " Finds made" + '<\/a><br>';
}
}
document.getElementById("side_bar").innerHTML = html;
}
I've tried replacing it with the code below which is taken from the piece of script which creates the sidebar on the right hand side.
function createSidebarEntry(marker2, sitedescription, distance) {
var div = document.createElement('div');
var html2 = '<b>' + sitedescription + '</b> (' + distance.toFixed(1) + ' miles) <br/>';
div.innerHTML = html2;
div.style.cursor = 'pointer';
div.style.marginBottom = '5px';
google.maps.event.addDomListener(div, 'click', function() {
google.maps.event.trigger(marker2, 'click');
});
google.maps.event.addDomListener(div, 'mouseover', function() {
div.style.backgroundColor = '#eee';
});
google.maps.event.addDomListener(div, 'mouseout', function() {
div.style.backgroundColor = '#fff';
});
return div;
}
This is what I've done so far. I can get the markers to appear on the map but I can't get the sidebar on the left hand side to render.
I've been working on this for a number of days now and I just seem to be going round in circles. I just wondered whether someone could take a look at this please and let me know where I've gone wrong.
Many thanks and kind regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么你会惊讶它不起作用?问题出在你的函数
makeSidebar()
中,它可能应该完成这项工作(?),但正如它所写的那样,它做了一些奇怪的事情......首先你创建一个新的div
> 您不要将其放置在 dom 中的任何位置(它可能应该放置在侧边栏中,但此函数中不使用侧边栏!)。该函数执行 for 循环,但它在第一次迭代中返回!所以实际上它什么也没做。继续调试您的代码。使用 Firebug 调试器来追踪它!
Why you are surprised it doesn't work? The problem is in your function
makeSidebar()
, which should probably do the job (?) but as it is written it does something strange... First you create a a newdiv
which you don't place anywhere in the dom (it should probably be placed in the sidebar, but the sidebar is not used in this function!). The function performs a for-loop but it returns in first iteration! So in fact it does nothing.Go ahead and debug your code. Use Firebug debugger to track it down!