0

我将一些来自 get-request 的 html 传递给我的 Jquery-dialog 函数。

但是在对话框内部,尽管我在调用对话框的页面中包含了 jquery,但我不能再使用任何 jquery 函数了。

如果我将它再次包含在对话框的 html 中,对话框的“确定”按钮将停止工作,并且在关闭对话框后,我从中调用对话框的页面上的所有其他内容也不再工作。

我希望在调用对话的页面中包含 jquery 就足以使对话能够访问 jquery,但情况似乎并非如此。

这是我的代码:

对话框.js:

var dialogDiv = $(document.createElement('div'));

function myDialogue(content) {
  dialogDiv.html(content);
  dialogDiv.dialog({autoOpen: false, modal: true, buttons: { "ok": function() {
  $(this).dialog("close");
  $(this).dialog("destroy").remove();
} } });
dialogDiv.dialog('open');
dialogDiv.scrollTop(0);
return true;
}

调用 myDialogue =>

主.html:

<script type="text/javascript" src="/path/to/jquery.js"></script>
<script type="text/javascript" src="/path/to/dialog.js"></script>

$.get("/path/to/controller/index", {param: "value"}, function(content) {
  myDialogue(content);
});

从我的控制器返回的 html 被传递给对话框:

<script type="text/javascript">
  $(document).ready(function() {
    $("#edit_div :checkbox").click(function () {
    // this NEVER gets called unless I include jquery again, but 
    // then the ok button and the rest of the page do not work anymore.
    alert("checked!!!");
    });
  });
</script>
<div id="edit_div">
<input type="checkbox" value="mycheck" name="mycheck"/>
....
4

1 回答 1

0

document.ready您包装函数的事件仅在第一次加载页面时被调用。

您可以尝试将该功能从document.ready包装器中取出,并将整个script标签放在您从控制器发送的标记的末尾。

于 2011-03-01T19:48:44.463 回答