1

当用户使用以下代码单击链接时,我正在将内容动态加载到 div 中:

function ahah(url, target) {
  document.getElementById(target).innerHTML = 'Opening form...';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {ahahDone(url, target);};
    req.open("GET", url, true);
    req.send("");
  }
}  

function ahahDone(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML=" AHAH Error:\n"+ req.status + "\n" +req.statusText;
    }
  }
}

function load(name, div) {
    ahah(name,div);
    return false;
}

这很好用,但是我无法让任何 javascript 在这个新内容中工作,例如 jquery 数据选择器,甚至只是一个 document.write hello world。代码中的js,只是不起作用。我已经直接在浏览器中加载了内容,它工作正常。

我不知所措,任何想法都非常感谢!

4

1 回答 1

0

如果您仍然使用 jquery,不妨尝试使用jquery.ajax(). 您可以在 jquery ajax 调用的回调函数中包含您需要的任何脚本<head>,然后调用您的 datepicker 或 w/e。

于 2010-09-15T16:02:04.567 回答