2

私は何が間違っているのか理解できませんか?私はすべてを本当にうまく書いたと思います:

HTML コードは次のようになります。

    <b>&nbspSelect Area</b>
    <select id="mySelect_1" onchange="showSelectedArea();" > 
    <option selected disabled hidden value=''></option>"
    <option value="1">Center</option> 
    <option value="2">New jersey</option>
    </select>

Javascriptはこれです:

    layer1.setVisibility(false);    
    layer2.setVisibility(false);    
    layer3.setVisibility(false);
    layer4.setVisibility(false);    

    }

    function showSelectedArea() {

    var e = document.getElementById("mySelect_1");
    var valueEpilogi_1 = e.options[e.selectedIndex].value;

    if (valueEpilogi_1 == "1") {
          layer3.setVisibility(true);   
    }

    }

問題はifまたは値の受け渡しにあるとは思いません.true == trueを設定すると、可視性がtrueに設定されません.selectタグで関数をトリガーすることに問題があると思います.

私の外部jsファイルをチェックして、何が問題なのか教えてください?? onbody load を実行する init 関数ですべてのレイヤーを定義しますか??問題はありますか? snk.to/f-cdh90xd4

4

1 に答える 1

1

select try that の値を読み取る必要があります。

var valueEpilogi_1 = document.getElementById('mySelect_1').value ;

edit : init() 関数の外で「layer」を使用する場合は、グローバル変数として定義する必要があります

例 :

function init(){
/* this variable is global, declaration without  'var' before, so it can be used out of the function*/
perioxes = new OpenLayers.Layer.Vector("Polygon Layer");
...
map.addLayer(perioxes); 
..
perioxes.setVisibility(false); 
...
}

function showSelectedArea() {

var valueEpilogi_1 = document.getElementById('mySelect_1').value ;

if (valueEpilogi_1 == "1") {
layer.setVisibility(true);   
}

}
于 2014-07-30T12:15:02.117 に答える