Jquery动态生成html

2017-06-11  本文已影响101人  疯狂的冰块

Jquery动态生成html:

    $.buildHTML = function (tag, htmltxt, attrs) {
        // you can skip html param
        if (typeof (htmltxt) != 'string') {
            attrs = htmltxt;
            htmltxt = null;
        }
        var h = '<' + tag;
        for (attr in attrs) {
            if (attrs[attr] === false) continue;
            h += ' ' + attr + '="' + attrs[attr] + '"';
        }
        return $(h += htmltxt ? ">" + htmltxt + "</" + tag + ">" : "/>");
    }
上一篇 下一篇

猜你喜欢

热点阅读