View中显示中国所有的省份
每个省份一个checkbox如果我数据库中有 上海 北京 两个省份那怎么在页面中把上海、北京两个checkbox的勾打上呢,其余的不变是通过JSON传值 还是怎么地?

解决方案 »

  1.   

    是啊 我也是这么想的$(document).ready(function() {
                JudgeCheckBox();
            });        function JudgeCheckBox() {
                var url = "/AreaConfiguration/GetCheckBoxStatus/";
                $.getJSON(url, function(data) {
                    $.each(data, function(i, item) {
                        $   ("#" + item ).attr("checked", true); //打勾
    //                    $(":CheckBox").each(function() {
    //                        if (($(this)[0].value == item[0])) {
    //                            $(this)[0].checked = true;
    //                        }
    //                    });
                    });
                });
            }        
    写的对不对呢
      

  2.   


    $(document).ready(function() {
                JudgeCheckBox();
            });        function JudgeCheckBox() {
                var url = "/AreaConfiguration/GetCheckBoxStatus/";
                $.getJSON(url, function(data) {
                    $.each(data, function(i, item) {
                        $("input:checkbox").each(function() {
                            if ($(this).val() = item[0]) {
                                $(this).attr("checked", 'true');
                            }
                        });
                    });
                });
            } 
    都不对额
      

  3.   


                     应该是这样的:
               $(this).attr("checked", 'checked');
                  
      

  4.   


    $(document).ready(function() {
                JudgeCheckBox();
            });
            function JudgeCheckBox() {
                var url = "/AreaConfiguration/GetCheckBoxStatus/";
                $.getJSON(url, { RegionName: ViewData["RegionName"], MoudleName: ViewData["MoudleName"] }, function(data) {
                    $.each(data, function(i, item) {
                        $(":checkbox").each(function() {
                            //alert($(this).val());
                            if ($(this).attr("value") = item["ProvinceId"]) {
                                $(this).attr("checked", true);
                            }
                        });
                    });
                });
            }      还是错的
    没人回答?
      

  5.   

    if ($(this).val() = item[0]) {双 == 啦