我有一个HTML表单,它将数据提交给cgi-bin脚本,然后再提供一些输出。
我看到this example显示了一个带有jQuery的模态框。这对于显示cgi-bin的输出非常完美!问题是这个例子适用于
<a href>
我无法用链接替换提交按钮。我该怎么办?
答案 0 :(得分:0)
$('#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
}
);
});