简体   繁体   English

在选择元素上使用jQuery更改功能时出现问题

[英]Problem using jQuery change function on a select element

I am using a simple select element. 我正在使用一个简单的选择元素。 On selecting a option in the select menu, I want to use jQuery's post method to update the div. 在选择菜单中选择一个选项时,我想使用jQuery的post方法更新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. 我想将change事件绑定到select元素。

$(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. 如果包含了jQuery文件,这应该可以正常工作。 Please check that jQuery is included properly. 请检查是否正确包含了jQuery。

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

This should give an alert, in case this does not, then jQuery is not working properly. 这应该发出警报,以防万一,则说明jQuery无法正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM