【发布时间】:2011-09-30 12:53:33
【问题描述】:
我有一个 HTML 表单,它将数据提交给一个 cgi-bin 脚本,该脚本又提供了一些输出。
我看到this example 显示了一个带有 jQuery 的模态框。这对于显示 cgi-bin 的输出来说是完美的!问题是这个例子适用于
<a href> 我不能用链接替换提交按钮。我该怎么办?
【问题讨论】:
我有一个 HTML 表单,它将数据提交给一个 cgi-bin 脚本,该脚本又提供了一些输出。
我看到this example 显示了一个带有 jQuery 的模态框。这对于显示 cgi-bin 的输出来说是完美的!问题是这个例子适用于
<a href> 我不能用链接替换提交按钮。我该怎么办?
【问题讨论】:
$('#your-form').submit(function(e){
e.preventDefault(); // make sure form is NOT submitted by the browser as this would make us navigate away from the current page and therefor render our modal window useless
$this = $(this); // cache $(this) for better performance
$.post( // submit the form via POST ...
$this.attr('action'), // ... to the action URL of our form
$this.serialize(), // ... with all the form fields as data
function(data) { // ... and with the server response ...
$(data).appendTo('body').paulund_modal_box().click(); // ... open the modal.
// note that the click() is only required for the rather quirky "plugin" that you linked to. I suggest using easybox or the like
}
);
});
【讨论】:
.appendTo('body') 应该可以解决问题,我猜“插件”需要将内容放在 DOM 中或其他东西中。