JavaScript 通过Ajax 动态加载CheckBox复选框

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/han1455418171/article/details/77718817
  //动态加载年份checkbox 
        function GetCompareYearByStationName(name) {
            var str = " <label class='control-label'>选择对比年限:</label>";
            $.ajax({
                type: "GET",  //默认是GET
                url: '@Url.Action("******", "*****")',
                data: "stationName=" + name,
                async: false,  //异步
                cache: false, //不加载缓存
                success: function (obj) {
                    var yearArray = new Array();
                    yearArray = obj.split(",");
                    for (var i = 0; i < yearArray.length; i++) {
                        if (i < yearArray.length - 3) {
                            str += "<label><input type='checkbox' name='checkbox' value='" + yearArray[i] + "' />" + yearArray[i] + "   </label>";
                        }
                        else {
                            str += "<label><input type='checkbox' name='checkbox' value='" + yearArray[i] + "' checked='checked' />" + yearArray[i] + "   </label>";
                        }
                    }
                    $("#compareyear").html(str);
                },
                error: function () {
                    alert("对比年限加载失败");
                }
            });
        }

展开阅读全文

没有更多推荐了,返回首页