0

我正在尝试使用 jQuery UI 的buttonset()功能在 Google Maps v3 中创建地图图例。我想以编程方式创建 div 标签,所以我的代码看起来像

var legend = document.createElement("div");
var input = document.createElement("input");
var label = document.createElement("label");
input.setAttribute("type", "checkbox");
input.setAttribute("id", "label");
label.setAttribute("for", "label");
label.innerHTML = "label";
input.appendChild(label);
legend.appendChild(input);
map.controls[google.maps.ControlPosition.BOTTOM_RIGHT].push(legend)
$(legend).buttonset()

但是,如果没有最后一行,我会得到一个复选框,但是当我添加最后一行时,复选框会消失。有没有办法让我在 Google 地图中使用 jQuery UI?还是我需要用直接的 Javascript 编写它?

4

1 回答 1

0

事实证明,我错误地订购了一些函数调用......这是我将代码更改为的内容。

var legendWrap = document.createElement("div");
var legend = document.createElement("div");
var input = document.createElement("input");
var label = document.createElement("label");
input.setAttribute("type", "checkbox");
input.setAttribute("id", "label");
label.setAttribute("for", "label");
label.innerHTML = "label";
input.appendChild(label);
legend.appendChild(input);
$(legend).buttonset() // <--- need to call buttonset() before appending 
                      //      it to the wrapped div
legendWrap.appendChild(legend) 
map.controls[google.maps.ControlPosition.BOTTOM_RIGHT].push(legendWrap)
                      // append the wrapped div instead
于 2013-07-22T19:27:40.097 回答