-1

ここにfunction findPlaces、ボックスなどの場所のオブジェクトを検索するコードがあります。

function findPlaces(boxes,searchIndex) {
   var request = {
       bounds: boxes[searchIndex],
       types: ["museum"]
   };

これはうまくいきますが、今...

リスト/メニューの値でこのタイプを変更したいので、次のようにします。

//JS CODE
function findPlaces(boxes,searchIndex) {
   var request = {
       bounds: boxes[searchIndex],
       types: document.getElementById("select").selectedIndex
   };

および HTML コード:

<label for="select"></label>
        <select name="select" id="select">
          <option>restaurant</option>
          <option>bar</option>
          <option>museum</option>
          <option>gas_station</option>
        </select>

このコードはリスト/メニューから値を取得せず、新しい値で関数を実行しません

どうすればそれを解決できますか?

4

2 に答える 2

0

この jQuery コードを試してください。要素を選択すると、インデックスが findPlaces に送信され、アラートが表示されます。

$("#select").change(function(){

        var values= $('#select option').map(function(){
                        return this.value;
                    }).get();
        var index=jQuery.inArray($(this).val(), values);
      
        findPlaces(boxes, index);//send index to your function

    });
 
 

デモはこちら

于 2013-09-16T11:50:13.590 に答える
0

次のように選択値を取得できます。

var boxes = ['a', 'b', 'c'];

function findPlaces(boxes, searchIndex) {
   var select = document.getElementById("select")
   return {
       bounds: boxes[searchIndex],
       types: select.options[select.selectedIndex].value
   };
}

document.getElementById("select").onclick = function() {

    var r = findPlaces(boxes, 2);
    alert(r.types);
};

例: http://jsfiddle.net/zaCZw/

于 2013-09-16T12:01:25.133 に答える