2017-01-26 26 views
0

我正嘗試使用小冊子創建自定義控件;在這裏,你可以看到jsfiddle:https://jsfiddle.net/1tca13f3/在小冊子中使用自定義控件的配置表單

當用戶點擊提交按鈕時,我需要從下拉菜單中選擇值,然後從文本框中讀取值。

這...

L.DomEvent.on(this._container, 'click', this._doSomething, this); 

...可預測的,不工作..我不能從輸入字段讀出值。我怎樣才能做到這一點?

回答

1

您遇到的主要問題是您只是提醒您的_doSomething()函數中的'clicked'字符串。你需要查看所有的值,然後你可以做任何你想要的值。這裏有一些快速代碼,至少可以讓你朝着正確的方向前進。

_doSomething: function(event){ 
if(event.target.className === 'leaflet-control-opt-submit') { 
    var select = document.querySelector('.leaflet-control-opt-dropdown');  
    var input = document.querySelector('.leaflet-control-opt-input'); 
    console.log(select.value, input.value) 
} 
} 

它首先檢查以確保event.target是提交按鈕,如果它是指從輸入查找的價值觀和現在,我們只CONSOLE.LOG()他們,你可以做任何你想從然後用值。

+1

謝謝。你的回答非常有幫助! – domne

相關問題