2013-09-02 1 views
0

Можно ли добавить целый блок кода с помощью appendChild? Это то, что я хочу добавить:Использование document.body.appendChild для добавления целого блока кода?

<script type="text/javascript" src="some.js"></script> 
<!--[if lt IE 8]> 
<link rel="stylesheet" type="text/css" href="styles-ie.css" media="all" /> 
<![endif]--> 
<!--[if lt IE 7]> 
<script type="text/javascript" src="85d6d1c5f8f9c87ae016eae0ee6994c7.js"></script> 
<![endif]--> 

Я предполагаю, что я не могу добавить его с помощью AppendChild?

+0

Почему бы вы добавить его в '' ? Не следует ли входить в ''? – Aashray

ответ

1

Если вы используете чистый JavaScript, вы могли бы использовать это:

var body = document.body; 
body.innerHTML += 'Whatever you want to append.'; 
+0

Psst: 'document.body' – Ryan

0
function addLABjs(callback) { 
    var script = document.createElement("script"); 
    script.setAttribute("src", "YourOtherScript.js"); 
    script.addEventListener('load', function() { 
     var script = document.createElement("script"); 
     script.textContent = "(" + callback.toString() + ")();"; 
     document.body.appendChild(script); 
    }, false); 
    document.body.appendChild(script); 
} 

// the guts of this userscript 


function main() { 
    $LAB.script("YourOtherScript.js").wait() 
     .script("YourOtherScript.js") 
     .script("YourOtherScript.js").wait(); 

    $(document).ready(function() { 
    }); 
} 

addLABjs(main);