在级联下拉列表中启用禁用功能 [英] enable disable function in cascading dropdown

查看:99
本文介绍了在级联下拉列表中启用禁用功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我建了一个带有三个级联下拉列表的mvc5应用程序,比如国家,州,城市。



现在我需要的是,如果我选择国家下拉列表意味着州下拉列表想要启用。到目前为止州下拉到城市下拉列表。



但默认情况下,州和城市下拉列表被禁用。在此先感谢





这是我的jquery:



  function  OnCountryChange(e)
{

var selectedCountryId = $(e).val();
var ddlStates = #sname< /跨度>;

$ .ajax({

url:' @ Url .Action(LoadStateList,Home)'
类型:' get'
dataType:' json'
contentType:< span class =code-string>'
application / json'
cache: false
数据:{ CountryId:selectedCountryId},
成功: function (数据){


$(ddlStates).empty();
$ .each (data, function (i,foo){

$(ddlStates).append(

$(< span class =code-string> < option>< / option>)。val(foo.Value).html(foo.Text)

);



});

},
错误: function (xhr,ajaxOptions,thrownError){

}
});

}

function OnStateChange(e){
var selectedStateId = $(e).val();
var ddlStates = #ciname< /跨度>;

$ .ajax({
url:' @ Url.Action( LoadCityList,Home)'
类型:' get'
dataType:' json'
contentType:' application / json'
cache: false
数据:{ StateId:selectedStateId},
成功:< span class =code-keyword> function
(data){


$(ddlStates).empty();
$ .each(data,< span class =code-keyword> function (i,foo){

$(ddlStates).append(

$( < option>< / option>)。val(foo.Value).html(foo.Text)
);



});

},
错误: function (xhr,ajaxOptions,thrownError){

}

});
}

解决方案

(e).val();
var ddlStates = #sname;


.ajax({

url:' @ Url.Action(LoadStateList,Home)'
类型:' get'
dataType:' json'
contentType:' application / json'
cache: false
data:{ CountryId: selectedCountryId},
成功: function (data){


(ddlStates).empty();

Hi Friends,

I built one mvc5 application with three cascading dropdown list, like country,state,city.

now what i need is if i select country dropdown list means state dropdown list wants to enable.and so far for state dropdown to city dropdown.

But by default state and city dropdown list is disabled. Thanks in Advance


here is my jquery:

    function OnCountryChange(e)
    {
       
        var selectedCountryId = $(e).val();
        var ddlStates = "#sname ";

$.ajax({
    
            url: '@Url.Action("LoadStateList", "Home")',
            type: 'get',
            dataType: 'json',
            contentType: 'application/json',
            cache: false,
            data: { "CountryId": selectedCountryId },
            success: function (data) {

              
                $( ddlStates).empty();
                $.each(data, function (i, foo) {

                    $(ddlStates).append(

$("<option></option>").val(foo.Value).html(foo.Text)

                    );
                   
                   
                  
                });
                
            },
            error: function (xhr, ajaxOptions, thrownError) {

            }
});
       
    }

    function OnStateChange(e) {
        var selectedStateId = $(e).val();
        var ddlStates = "#ciname";
       
        $.ajax({
            url: '@Url.Action("LoadCityList", "Home")',
            type: 'get',
            dataType: 'json',
            contentType: 'application/json',
            cache: false,
            data: { "StateId": selectedStateId },
            success: function (data) {


                $(ddlStates).empty();
                $.each(data, function (i, foo) {

                    $(ddlStates).append(

$("<option></option>").val(foo.Value).html(foo.Text)
                    );
                    
                   

                });
                
            },
            error: function (xhr, ajaxOptions, thrownError) {

            }
           
        }); 
    }

解决方案

(e).val(); var ddlStates = "#sname ";


.ajax({ url: '@Url.Action("LoadStateList", "Home")', type: 'get', dataType: 'json', contentType: 'application/json', cache: false, data: { "CountryId": selectedCountryId }, success: function (data) {


( ddlStates).empty();


这篇关于在级联下拉列表中启用禁用功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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