jQuery-选择菜单-OnChange重新评估值 [英] JQuery - Select menu - OnChange Reevaluate Value

查看:81
本文介绍了jQuery-选择菜单-OnChange重新评估值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有国家名称列表的选择菜单.我正在使用jquery来获取当前选定选项的值.我将此附加到用于填充自动完成字段的远程源文件的url上.

I have a select menu with a list of country names. I'm using jquery to get the value of the currently selected option. I'm appending this to the url of the remote source file that I am using to populate the autocomplete field.

我需要在国家/地区选择菜单的更改功能内更新选择菜单的值.当前,它在页面首次加载时使用选择菜单的值.

I need to update the value of the select menu within the function onchange of the country select menu. Currently it uses the value of the select menu when the page is first loaded.

我试图让它重新评估值onchange,以改变我试图在远程页面上运行的mysql查询的结果.

I'm trying to have it reevaluate the value onchange as to alter the results of the mysql query I am trying to run on the remote page.

<script type="text/javascript">

  $(function() {

  $('#from_country').val("");

  $("#city").autocomplete({
    source: "json-list.php?country=" + $( "#from_country" ).val(),
    minLength: 3,
    select: function(event, ui) {
      $('#from_zip').val(ui.item.postal_code);
    }
  });
});

</script>

<select name="from_country"  id="from_country" >
  <option value='US'>United States</option>
  <option value='AU'>Australia</option>
</select>

推荐答案

您可以使用change事件处理程序:

You can use change event handler:

$('#from_country').change(function(){
  var val = this.value;
  $("#city").autocomplete({
    source: "json-list.php?country=" + val,
    minLength: 3,
    select: function(event, ui) {
      $('#from_zip').val(ui.item.postal_code);
    }
  });
}).change()

这篇关于jQuery-选择菜单-OnChange重新评估值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆