使用document.createElement追加lt IE


append lt IE using document.createElement

这是我的代码:

function addTag(name, attributes, sync, cond) {
var el = document.createElement(name),
    attrName;
for (attrName in attributes) {
  el.setAttribute(attrName, attributes[attrName]);
}
sync ? document.write(outerHTML(el)) : headEl.appendChild(el);

}

 function outerHTML(node){
// if IE, Chrome take the internal method otherwise build one
return node.outerHTML || (
    function(n){
        var div = document.createElement('div'), h;
        div.appendChild(n);
        h = div.innerHTML;
        div = null;
        return h;
    })(node);

}

这是我的电话:

addTag('script',{"src":"'/'/oss.maxcdn.com'/html5shiv'/3.7.2'/html5shiv.min.js"},1,'lt IE 9');

如何在代码中放置less than标记?参数为cond

您可以尝试:

function addTag(name, attributes, sync, cond) {
    var el = document.createElement(name),
        attrName,
        condElement
    ;
    for (attrName in attributes) {
        el.setAttribute(attrName, attributes[attrName]);
    }
    switch (cond) {
        case 'lt IE 9':
            el = document.createComment(
                '[if lt IE 9]>' + outerHTML(el) + '<![endif]'
            );
            break;
    }
    sync ? document.write(outerHTML(el)) : headEl.appendChild(el);
}