[英]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. 感谢您的帮助。
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无法正常工作。
$('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/val/
http://api.jquery.com/selected-selector/ http://api.jquery.com/selected-selector/
jQuery - setting the selected value of a select control via its text description jQuery-通过文本说明设置选择控件的选择值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.