Javascript 在下拉列表更改时运行jQuery函数
我编写了一个jQuery函数,当前在Click事件上运行。我需要更改它,以便它在下拉框(选择选项)值更改时运行。这是我的密码:Javascript 在下拉列表更改时运行jQuery函数,javascript,jquery,Javascript,Jquery,我编写了一个jQuery函数,当前在Click事件上运行。我需要更改它,以便它在下拉框(选择选项)值更改时运行。这是我的密码: <form id="form1" name="form1" method="post" action=""> <label> <select name="otherCatches" id="otherCatches"> <option value="*">All</option>
<form id="form1" name="form1" method="post" action="">
<label>
<select name="otherCatches" id="otherCatches">
<option value="*">All</option>
</select>
</label>
</form>
使用change()
而不是click()
:
.change()非常适合列表我知道这类注释是不受欢迎的,但是:在Google上搜索
jquery change
会为您提供指向change()
函数的链接作为第一次点击:
$("#otherCatches").click(function() {
$.ajax({
url: "otherCatchesMap.php>",
success: function(msg) {
$("#results").html(msg);
}
});
});
jQuery(document).ready(function(){
$("#otherCatches").change(function() {
$.ajax({
url: "otherCatchesMap.php>",
success: function(msg){
$("#results").html(msg);
}
});
});
});
$(function() {
$("#otherCatches").change(function() {
$(this).val() // how to get the value of the selected item if you need it
});
});
$("#otherCatches").change(function () {
//// Your code
});