开发者

Problem using jQuery change function on a select element

开发者 https://www.devze.com 2023-03-30 16:30 出处:网络
I am using a simple select element. On selecting a option in the select menu, I want to use jQuery\'s pos开发者_JAVA百科t method to update the div.

I am using a simple select element. On selecting a option in the select menu, I want to use jQuery's pos开发者_JAVA百科t method to update the div.

<select class="article">
    <option value="title1">title1</option>
    <option value="title2">title2</option>
    <option value="title3">title3</option>
</select>

I want to bind the change event to the select element.

$(document).ready(function() {
    $(".article").change(function() {
        var src = $(this).val();
        alert(src);
    });
});

This does not work. I don't see the alert box on changing the select box.

I appreciate any help.


It does work fine

Working demo


This should work fine, have you included jQuery files. Please check that jQuery is included properly.

$(document).ready(function() {
    alert('hello');
});

This should give an alert, in case this does not, then jQuery is not working properly.


$('select.foo option:selected').val();    // get the value from a dropdown select

More about the subject;

http://api.jquery.com/val/

http://api.jquery.com/selected-selector/

jQuery - setting the selected value of a select control via its text description

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号