【问题标题】:Integrate html form with jQuery plugin将 html 表单与 jQuery 插件集成
【发布时间】:2011-09-30 12:53:33
【问题描述】:

我有一个 HTML 表单,它将数据提交给一个 cgi-bin 脚本,该脚本又提供了一些输出。

我看到this example 显示了一个带有 jQ​​uery 的模态框。这对于显示 cgi-bin 的输出来说是完美的!问题是这个例子适用于 <a href> 我不能用链接替换提交按钮。我该怎么办?

【问题讨论】:

    标签: jquery html cgi


    【解决方案1】:
    $('#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
            }
        );
    });
    

    【讨论】:

    • 我尝试替换“$(document).ready(function(){$('.paulund_modal').paulund_modal_box();});”用你的代码,我用我的表单类替换了“你的表单”;但它不起作用。
    • 您是否将表单前的“#”替换为“。”那么呢?
    • 我现在有了这个 "$('.feedbackform').submit(function(e){"; 执行了 cgi-bin 脚本,但我没有看到模态框,也没有输出(我看到页面,因为没有发生任何事情)。
    • 查看更新....appendTo('body') 应该可以解决问题,我猜“插件”需要将内容放在 DOM 中或其他东西中。
    • 不,这就像没有执行点击(但是,我看到 cgi-bin 实际运行)。顺便说一句,这是我的 cgi-bin: echo "Content-Type: text/html" echo Parameter modified.
    猜你喜欢
    • 2013-09-08
    • 2012-07-15
    • 1970-01-01
    • 2012-08-31
    • 1970-01-01
    • 2016-07-05
    • 2020-07-16
    • 1970-01-01
    • 2011-01-05
    相关资源
    最近更新 更多