首页 > Web开发 > 详细

json与页面动态绑定

时间:2019-05-08 20:35:31      阅读:136      评论:0      收藏:0      [点我收藏+]
    function fnBindHtml(html, tempName, data) {
            $(html).find(tempName).each(function () {
                var _this = this;
                var thisNmae = _this.getAttribute(‘name‘) ? _this.getAttribute(‘name‘):"err";
                switch (_this.tagName) {
                    case "DIV": { _this.innerHTML = data[thisNmae]; }
                        break;
                    case "P": { _this.innerHTML = data[thisNmae]; }
                        break;
                    case "SPAN": { _this.innerHTML = data[thisNmae]; }
                        break;
                    case "INPUT": { _this.value = data[thisNmae]; }
                        break;
                    default: { _this.innerHTML = data[thisNmae]; };
                        break;
                };
            });
            //return html;
        };

        function fnCreatHtml(rootid, tempName, data) {
            if (data == null || data.length == 0) { return false; }

            for (var i = 0; i < data.length; i++) {
                var rootDivCope = $(rootid).eq(0).clone(true);
                fnBindHtml(rootDivCope, tempName, data[i]);// rootDivCope =                
                $(rootDivCope).show();
                $(rootid).eq(0).after(rootDivCope);
            };
        }

        function fnShowNote(strCode, id) {
            $.ajax({
                url: "/TraceApi/GetOneCameraInfo",
                data: { code: strCode },
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: true,//同步异步设置,false同步,true异步
                success: function (res) {
                    if (res.code != "1000") {
                        return;
                    };
                    var modelList = res.data;
                    if (modelList == null || modelList.length == 0) { return; }
                    fnCameraNote(modelList, id);
                }
            });
        };

 

json与页面动态绑定

原文:https://www.cnblogs.com/Blogs-Wang/p/10833579.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!