D3.js: get value of selected option?

前端 未结 4 1013
刺人心
刺人心 2020-12-09 16:41

I want to get the value of the selected option from a dropdown list, in D3.js.


                        
    
提交评论

  • 2020-12-09 16:59

    Use the .property() method:

    d3.select("#objectID").property("value")
    
    0 讨论(0)
  • 2020-12-09 17:03

    You don't need to use D3 to do that:

    var sel = document.getElementById('myselect');
    console.log(sel.options[sel.selectedIndex].value)
    
    0 讨论(0)
  • 2020-12-09 17:07

    I've also seen

    d3.select("#objectID")[0][0].value
    

    But I'm quite sure this is generally a bad idea...

    0 讨论(0)
  • 提交回复
    热议问题