如何获取值选择名称

时间:2017-03-06 23:12:47

标签: javascript dojo

我现在开始编程,我需要知道这段代码的价值是什么文字。 JS代码将是这个不可展开的列表中的“on click”事件。提前谢谢!!

 <select name="select1" data-dojo-type="dijit/form/Select">
        <option value="Artesania">Artesania</option>
        <option value="Banco" selected="selected">Banco</option>
        <option value="Bar">Bar</option>
        <option value="Bodega">Bodega</option>
        <option value="Boutique">Boutique</option>
        <option value="Discoteca">Discoteca</option>

1 个答案:

答案 0 :(得分:0)

var selectbox = document.getElementById('select');
selectbox.addEventListener('change', function(){
  console.log(this.value);
  //do whatever you want with the value
});
<select name="select1" data-dojo-type="dijit/form/Select" id='select'>
        <option value="Artesania">Artesania</option>
        <option value="Banco" selected="selected">Banco</option>
        <option value="Bar">Bar</option>
        <option value="Bodega">Bodega</option>
        <option value="Boutique">Boutique</option>
        <option value="Discoteca">Discoteca</option>
</select>