Simple modal in jQuery(jQuery中的简单模态)
问题描述
我在 jQuery 中使用 SimpleModal,并且有一个确认对话框.如果结果是Yes
,我必须在这个对话框中调用my.php
.但是,我已经完成了代码,我仍在寻找想法.我该怎么做?
I am using SimpleModal in jQuery, and I have one confirm dialog. If the result is Yes
, I have to call my.php
into this dialog. However, I have done the code, and I am still searching for ideas. How can I do it?
$(document).ready(function () {
$('#confirmDialog input.confirm, #confirmDialog a.confirm').click(function (e) {
e.preventDefault();
// Example of calling the confirm function.
// You must use a callback function to perform the "yes" action.
confirm("Continue", function () {
alert("OK");
});
});
});
function confirm(message, callback) {
$('#confirm').modal({
close:false,
position: ["20%",],
overlayId:'confirmModalOverlay',
containerId:'confirmModalContainer',
onShow: function (dialog) {
dialog.data.find('.message').append(message);
// If the user clicks "yes"
dialog.data.find('.yes').click(function () {
$.get('my.php', function(data){
// Create a modal dialog with the data.
// Here: How do I write the same window?
});
// Call the callback
// Close the dialog
$.modal.close();
});
}
});
}
在这里,我遇到了如何从 Ajax 结果中将其写入同一个窗口 Confirmdialog 的问题.我该怎么做?
Here I have the problem of how to write it the same window Confirmdialog from an Ajax result. How can I do it?
推荐答案
我不确定确认功能是否最适合您的需求,但这样的事情应该可以工作:
I'm not sure that the confirm function best fits your needs, but something like this should work:
function confirm(message, callback) {
$('#confirm').modal({
close:false,
position: ["20%",],
overlayId:'confirmModalOverlay',
containerId:'confirmModalContainer',
onShow: function (dialog) {
dialog.data.find('.message').append(message);
// If the user clicks "yes"
dialog.data.find('.yes').click(function () {
$.get("my.php", function (data) {
/* Sample response:
* <div id="title">my title</div>
* <div id="message">my message</div>
*
*/
var resp = $("<div/>").append(data);
var title = resp.find("#title").html(),
message = resp.find("#message").html();
dialog.data.find(".header span").html(title);
dialog.data.find(".message").html(message);
dialog.data.find(".buttons .yes").hide();
dialog.data.find(".buttons .no").html("Close");
// No need to call the callback or $.modal.close()
});
});
}
});
}
这篇关于jQuery中的简单模态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:jQuery中的简单模态


基础教程推荐
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01