我编写了一个当前在Click Event上运行的jQuery函数。我需要更改它,以便在更改下拉框(Select- Option)值时运行它。这是我的代码:
<form id="form1" name="form1" method="post" action="">
<label>
<select name="otherCatches" id="otherCatches">
<option value="*">All</option>
</select>
</label>
</form>
$("#otherCatches").click(function() {
$.ajax({
url: "otherCatchesMap.php>",
success: function(msg) {
$("#results").html(msg);
}
});
});
答案 0 :(得分:33)
使用change()
代替click()
:
jQuery(document).ready(function(){
$("#otherCatches").change(function() {
$.ajax({
url: "otherCatchesMap.php>",
success: function(msg){
$("#results").html(msg);
}
});
});
});
答案 1 :(得分:22)
$(function() {
$("#otherCatches").change(function() {
$(this).val() // how to get the value of the selected item if you need it
});
});
答案 2 :(得分:11)
$("#otherCatches").change(function () {
//// Your code
});