有没有办法在传单层控制中禁用单选按钮?

时间:2014-08-20 20:54:30

标签: javascript css leaflet

我正在寻找一种方法来选择/禁用我的基本地图中的单个单选按钮。这是我的代码。

这将为myleaflet图层

创建baseMap
baseMap = {
    Map View: mapQuestOpenEnglish
    Satelite View: mapQuestAerial
}

mapControl = L.control.layers(baseMap)

最后我将mapControl添加到地图中,它会生成以下html

<div class="leaflet-control-layers leaflet-control" aria-haspopup="true">
  <a class="leaflet-control-layers-toggle" href="#" title="Layers"></a>
  <form class="leaflet-control-layers-list">
    <div class="leaflet-control-layers-base">
      <label>
        <input type="radio" class="leaflet-control-layers-selector" name="leaflet-base-layers" checked="checked">
        <span> 
          <span class="default-map">Map View</span>
        </span>
      </label>
      <label>
        <input type="radio" class="leaflet-control-layers-selector" name="leaflet-base-layers">
        <span> 
          <span class="staelite-map">Satelite View</span>
        </span>
      </label>
    </div>
  </form>
</div>

我想要一种能够选择/禁用此单选按钮的方法。

<input type="radio" class="leaflet-control-layers-selector" name="leaflet-base-layers">

有没有简单的方法可以做到这一点?非常感谢任何帮助

1 个答案:

答案 0 :(得分:1)

好的,不是很干净,但有效......

您可以通过它的相应跨度标签类选择所需的无线电元素。这是一个简单的JS方法:

function SelectRadio(span_class) {
    var span = document.getElementsByClassName(span_class)[0];
    var radio = span.parentNode.parentNode.getElementsByTagName('radio')[0];
    return radio;
}

你只需这样称呼:

var element = SelectRadio('staelite-map');
/* Here you'll have the DOM Element. Just use it to enable/disable,
      set selection, or anything else */