我正在尝试在我的 Javascript 中获得一个非常基本且简单的对话框,实际上我正在尝试从 jqueryui 网站复制与此示例非常相似的内容:
<script type="text/javascript">
$(function() {
$("#dialog").dialog({
bgiframe: true,
height: 140,
modal: true
});
});
</script>
<div class="demo">
<div id="dialog" title="Basic modal dialog">
<p>Adding the modal overlay screen makes the dialog look more prominent because it dims out the page content.</p>
</div>
...
为了实现这一点,我运行了一个函数 testJQ 但我无法获得预期的效果。添加了 div 及其内部 p,我可以看到 p 的内容,但看不到“基本模式对话框”,也无法在页面上移动它。我错过了什么吗?这是我的代码:
function testJQ() {
var doc = jetpack.tabs.focused.contentDocument;
var win = jetpack.tabs.focused.contentWindow;
$.get("http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js",
function(js) {
var script = doc.createElement("script");
script.innerHTML = js;
doc.body.appendChild(script);
$.get("http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js",
function(js) {
var script = doc.createElement("script");
script.innerHTML = js;
doc.body.appendChild(script);
$.get("http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css",
function(js) {
var style = doc.createElement("style");
style.innerHTML = js;
doc.getElementsByTagName('HEAD')[0].appendChild(style);
var script = doc.createElement("script");
script.innerHTML = js;
doc.body.appendChild(script);
script = doc.createElement("script");
script.innerHTML += '$(function() {';
script.innerHTML += '$("#dialog").dialog({'
script.innerHTML += ' bgiframe: true, height: 140, modal: true';
script.innerHTML += ' });';
script.innerHTML += '});';
doc.body.appendChild(script);
divDialog = doc.createElement("div");
divDialog.setAttribute('id', 'dialog');
divDialog.setAttribute('title', 'Basic Dialog');
divDialog.innerHTML = '<p>This is the default dialog which is useful
for displaying information. The dialog window can be moved, resized
and closed with the X icon.</p>';
doc.body.appendChild(divDialog);
});
});
});
}