简体   繁体   English

使用document.createElement附加lt IE

[英]append lt IE using document.createElement

Here is my code: 这是我的代码:

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);

} }

Here is my call: 这是我的电话:

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

How do I place less than tags in my code? 如何在代码中放置less than标签? The argument is cond 这个论点是cond

You can try that: 你可以尝试:

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM