All browsers currently support a javascript text property, and will evaluate the text when a new script element (without a src attribute) is added to the document.
innerHTML or adding child nodes to a script element do not evaluate the script in all browsers.
function addCode(code){
var JS= document.createElement('script');
JS.text= code;
document.body.appendChild(JS);
}
//test case
var s= 'document.body.ondblclick=function(e){
'+
'e=window.event? event.srcElement:e.target;
'+
'alert(e.id || e.tagName);
'+
'}
alert("ready to double click!");';
addCode(s);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…