jQuery AJAX下拉菜单反复重置 [英] JQuery AJAX Dropdown Repeatedly Reset

查看:206
本文介绍了jQuery AJAX下拉菜单反复重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自这个问题: Jquery根据tr标签的属性填充下拉列表

还有另一种方法可以完成此操作吗?我找不到这个背后的算法

Is there another way to accomplish this? I can't find the algorithm behind this

jQuery代码VehicleCategory():

JQuery Code VehicleCategory():

function VehicleCategory(){

            $("#category" + counterVehicle).empty();
            $("#category" + counterVehicle).append("<option>Loading.....</option>");
            $("#brand"  + counterVehicle).append("<option value=''>-Select Brand-</option>");
            $("#model" + counterVehicle).append("<option value=''>-Select Model-</option>");
            $("#year" + counterVehicle).append("<option value=''>-Select Year-</option>");
            $("#mileage" + counterVehicle).append("<option value=''>-Select Mileage-</option>");
            $.ajax({
                type:"POST",
                url:"car_dropdown.php?comboBoxName=category",
                contentType:"application/json; charset=utf-8",
                dataType:"json",
                success: function(data){
                    $("#category" + counterVehicle).empty();
                    $("#category" + counterVehicle).append("<option value=''>-Select Category-</option>");
                    $.each(data,function(i,item){
                         $("#category" + counterVehicle).append('<option value="'+ data[i].category +'">'+ data[i].category +'</option>');
                    });

                },

                complete: function(){

                }

            });
        }

当我加载页面时:

当我单击第一个下拉列表时:

When I click the first dropdown:

当我一次又一次单击下拉列表^^'时:

When I click the dropdown again and again ^^':

推荐答案

您多次调用VehicleCategory().如果需要执行此操作,请清空先前的内容.

You are calling the VehicleCategory() multiple times.. If you need to do this, then empty the prior contents..

更改..

$("#brand"  + counterVehicle).append("<option value=''>-Select Brand-</option>");

收件人:

$("#brand"  + counterVehicle).html("<option value=''>-Select Brand-</option>");

这篇关于jQuery AJAX下拉菜单反复重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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