寻找关键词“简单jquery对话框示例”的所有答案,但是没有看到任何简洁明了的独立.html文件的实用示例。即使下载了几本jQuery的完整书籍,也没有看到这样的示例。
我找到的示例是显示警报消息“Hello World”的对话框..对于交互来说并不是非常有用。 我认为真实世界的示例应该是捕获输入并将其发送回页面,而无需返回服务器。 服务器发布可以是后续步骤。
有人能否推荐一个类似这些的代码参考?谢谢
编辑#3
我在下面粘贴了一个解决方案的新帖子。它是一个完全独立的文件,具有现成的包含文件。它对我有效。
编辑#2
我更新了head块以包含缺失的css。对话框内容现在没有显示,但对话框框仍未打开...控制台中没有错误。
<style>
#dialog {
display:none;
}
</style>
编辑-尝试#1
根据@rob-schmuecker的答案,我尝试了下面的代码。我在jsFiddle上看到它可以工作,但是我的实现不起作用。在我的浏览器中控制台没有显示任何错误。但我看到两个问题:
- dialog-box div内容直接加载到页面中
- 单击load dialog按钮无效
这段代码有什么问题吗?...也许是我的jquery包含调用吗?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.js" type="text/javascript"></script>
<script type="text/javascript">
//Initialize dialog
$("#dialog").dialog({
autoOpen: false,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 1000
}
});
//Open it when #opener is clicked
$("#opener").click(function () {
$("#dialog").dialog("open");
});
//When the button in the form is clicked, take the input value and set that as the value of `.myTarget`
$('.formSaver').on('click', function () {
$('.myTarget').text($('.myInput').val());
$("#dialog").dialog('close');
});
</script>
<style>
#dialog {
display:none;
}
</style>
</head>
<body>
<div>Here is the rest of the page. Hopefully we can get the value from the dialog form?! Should display <span class="myTarget">here</span> when finished.</div>
<div id="dialog" title="Basic dialog">
<p>This is an animated dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
<input class="myInput" type="text" />
<button class="formSaver">Save me!</button>
</div>
<button id="opener">Open Dialog</button>
</body>
</html>
prompt()
吗? - Karl-André Gagnon