当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - How to get selected value from dropdownlist using chosen.js

问题描述:

I am trying to get two parameters from dropdown list change event. Dropdown list uses chosen.js

First I would like to get a name of the dropdown list

Second I would like to get a value of an item that has been selected

I found this code in documentation:

$('.my_select_box').on('change', function(evt, params) {

do_something(evt, params);

});

but when I trigger it, params are undefined. Have been looking everywhere, but cannot find out how to do it. Can you help please?

网友答案:

With jQuery, use $(this).val() into your callback function, check the Fiddle :

<script>
$('.my_select_box').on('change', function(evt, params) {
    // The name of your select
    alert($(this).attr('name'));
    // The value
    alert($(this).val());
});
</script>

Then

<select name="my_drop_down" class="my_select_box">
    <option value="one">One</option>
    <option value="two">Two</option>
    <option value="three">Three</option>
</select>
分享给朋友:
您可能感兴趣的文章:
随机阅读: