我目前在我的网站上设置了 AJAX 脚本,该脚本根据下拉菜单[id="afl_player_ID"]
中的选择来更新表格。
如果[id="afl_player_ID"]
或[id="afl_stat_ID"]
被更改,我想做的就是运行相同的脚本。
如何将此功能添加到此代码中?
<script type="text/javascript">
jQuery(document).ready(function ($) {
var valueCheck;
jQuery("#afl_player_ID").on("change", function () {
player_ID = $("#afl_player_ID").val();
stat_ID = $("#afl_stat_ID").val();
jQuery.ajax({
type: "POST",
url: "/wp-admin/admin-ajax.php",
data: {
action: "call_advanced_player_basic_gamelog",
player_ID: player_ID,
stat_ID: stat_ID
},
success: function (output) {
jQuery("#advanced_player_basic_gamelog").html(output);
}
});
}).change();
});
</script>
答案 0 :(得分:1)
使用@Farooq Khan在评论中建议的以下代码
<script type="text/javascript">
jQuery(document).ready( function($) {
var valueCheck;
jQuery('#afl_player_ID,#afl_stat_ID').on( 'change', function () {
player_ID = $('#afl_player_ID').val();
stat_ID = $('#afl_stat_ID').val();
jQuery.ajax({
type: "POST",
url: "/wp-admin/admin-ajax.php",
data: {
action: 'call_advanced_player_basic_gamelog',
player_ID: player_ID,
stat_ID: stat_ID,
},
success:function(output){
jQuery('#advanced_player_basic_gamelog').html( output );
}
});
}).change();
});
</script>