[英]How to only run a JQuery function if a certain field is chosen in a drop down
[英]Run jQuery function on drop down change
我編寫了一個當前在Click事件上運行的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);
}
});
});
使用change()
而不是click()
:
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
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.