0

buttonset()jQuery UI の関数を使用して、Google マップ 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 に答える