get-request からの html を Jquery-dialog 関数に渡します。
ただし、ダイアログ内では、ダイアログを呼び出すページにjqueryを含めましたが、jquery関数を使用できなくなりました。
ダイアログのhtmlに再度含めると、ダイアログの「OK」ボタンが機能しなくなり、ダイアログを閉じた後、ダイアログを呼び出したページ上の他のすべてのものも機能しなくなります。
ダイアログを呼び出すページにjqueryを含めれば、ダイアログがjqueryにアクセスできるようになると思いますが、そうではないようです。
ここに私が持っているコードがあります:
dialog.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 への呼び出し =>
main.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"/>
....