动态依赖选择菜单jQuery PHP版本 [英] Dynamic dependent select menus jQuery PHP version

查看:52
本文介绍了动态依赖选择菜单jQuery PHP版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在上一个问题中,我做了动态相关选择菜单我发布了此信息示例代码: http://jsfiddle.net/Bs5Db/50/. 这是特定jquery脚本的HTML版本. 用户@jSweazy帮助我指出,每次我从第一个菜单中选择新状态时,都应该更新jquery.uniform脚本. 该示例的工作版本在这里: http://jsfiddle.net/Bs5Db/53/ . 我知道默认选项对于菜单来说太大了,但是很容易修复....

In a previous question i made Dynamic dependent select menus i posted this example code: http://jsfiddle.net/Bs5Db/50/. This is the HTML version of the particular jquery script. The user @jSweazy helped me pointing that i should update the jquery.uniform script every time i select a new state from the first menu. The working version of the example is here: http://jsfiddle.net/Bs5Db/53/. I know that the default option is too large for the menu but that is easily fixed....

我现在的问题是我实际上使用了脚本的PHP版本.在那个版本中,用$ .uniform.update()更新jquery.uniform;没有成功.实际上,当我插入更新命令时,第二个菜单不再可见.

My problem now is that i actually use the PHP version of the script. In that version updating the jquery.uniform with $.uniform.update(); doesnt do the trick. Actually the second menu isnt visible anymore when i insert the update command.

PHP版本如下...

The PHP version is the following...

 $(document).ready(function(){
 function populate() {
 if($('#state').val() == 'AK' || $('#state').val() == 'DC') // Alaska and District     Columbia have no counties
{
   $('#county_drop_down').hide();
   $('#no_county_drop_down').show();
    } else {
   fetch.doPost('../getCounties.php');
   }
  }
  $('#state').change(populate);
  var fetch = function() {
  var counties = $('#county');
  return {
  doPost: function(src) {
 $('#loading_county_drop_down').show(); // Show the Loading...
 $('#county_drop_down').hide(); // Hide the drop down
 $('#no_county_drop_down').hide(); // Hide the "no counties" message (if it's the case)
 if (src) $.post(src, { state_code: $('#state').val() }, this.getCounties);
    else throw new Error('No SRC was passed to getCounties!');
},

getCounties: function(results) {

    if (!results) return;
            var allCounties = $("<option value=\"All\">All Counties</option>");
  counties.html(results);
  counties.prepend(allCities);
  counties.val("All").attr('selected',true);


$('#loading_county_drop_down').hide(); // Hide the Loading...

$('#county_drop_down').show(); // Show the drop down

}   
 }

 }();

 populate();
 });

用于查询数据库并检索每个州的县的getCounties.php可以正常工作. 州和县是两个选择菜单的名称. 因此,如果有人可以在此版本的脚本中给我一些有关如何实现县菜单更新的建议,我将不胜感激. 提前感谢您抽出宝贵的时间来阅读!

The getCounties.php that is querying the database and retrieves the counties of each state works fine. state and county are the names of the two select menus. So if anyone can give me an advice of how to achieve the update of the counties menu in this version of the script i would be grateful. Thanx in advance for taking the time to read!

推荐答案

我意识到即使在这种情况下,您也必须更新jquery.uniform,但是由于还有其他样式化的元素,例如单选按钮,复选框等. 您必须插入$ .uniform.update('select').因此,代码的最后一部分变为...

I realized that even in this case you have to update the jquery.uniform but since there are other styled elements such as radio buttons, checkboxes etc. You have to insert $.uniform.update('select').So the last part of the code becomes...

 $('#loading_county_drop_down').hide(); // Hide the Loading...
 $.uniform.update('select')
 $('#county_drop_down').show(); // Show the drop down

这篇关于动态依赖选择菜单jQuery PHP版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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