日期:2014-05-17  浏览次数:20683 次

在InnerHTML中执行js代码(一位教授解决了这个问题)
<script>
/* innerhtml.js  
* Copyright Ma Bingyao <andot@ujn.edu.cn>  
* Version: 1.9  
* LastModified: 2006-06-04  
* This library is free.  You can redistribute it and/or modify it.  
* http://www.coolcode.cn/?p=117  
*/  

var global_html_pool = [];   
var global_script_pool = [];   
var global_script_src_pool = [];   
var global_lock_pool = [];   
var innerhtml_lock = null;   
var document_buffer = "";   
  
function set_innerHTML(obj_id, html, time) {   
    if (innerhtml_lock == null) {   
        innerhtml_lock = obj_id;   
    }   
    else if (typeof(time) == "undefined") {   
        global_lock_pool[obj_id + "_html"] = html;   
        window.setTimeout("set_innerHTML('" + obj_id + "', global_lock_pool['" + obj_id + "_html']);", 10);   
        return;   
    }   
    else if (innerhtml_lock != obj_id) {   
        global_lock_pool[obj_id + "_html"] = html;   
        window.setTimeout("set_innerHTML('" + obj_id + "', global_lock_pool['" + obj_id + "_html'], " + time + ");", 10);   
        return;   
    }   
  
    function get_script_id() {   
        return "script_" + (new Date()).getTime().toString(36)   
          + Math.floor(Math.random() * 100000000).toString(36);   
    }   
  
    document_buffer = "";   
  
    document.write = function (str) {   
        document_buffer += str;   
    }   
    document.writeln = function (str) {   
        document_buffer += str + "\n";   
    }   
  
    global_html_pool = [];   
  
    var scripts = [];   
    html = html.split(/<\/script>/i);   
    for (var i = 0; i < html.length; i++) {   
        global_html_pool[i] = html[i].replace(/<script[\s\S]*$/ig, "");   
        scripts[i] = {text: '', src: '' };   
        scripts[i].text = html[i].substr(global_html_pool[i].length);   
        scripts[i].src = scripts[i].text.substr(0, scripts[i].text.indexOf('>') + 1);   
        scripts[i].src = scripts[i].src.match(/src\s*=\s*(\"([^\"]*)\"|\'([^\']*)\'|([^\s]*)[\s>])/i);   
        if (scripts[i].src) {&nbs