jquery - 如何在提交 html 表单时打开 jQuery 模态窗口

标签 jquery html forms modal-dialog

我正在使用一个简单的 html 表单将产品从我的网站提交到我远程托管的 Mal 电子商务购物车。 我需要在提交表单时打开一个模式窗口(包含 iframe)。我无法访问购物车的服务器端编程,那么有没有办法使用 onclick html 事件属性启动 jQuery 模式窗口?

现在,表单底部的 onclick 属性会打开一个 js 浏览器警报...基本上我需要用我的 jQuery 模态对话框窗口替换此 js 警报。

有人可以帮忙吗?

这是我的表格:

<form action="http://ww7.aitsafe.com/cf/add.cfm" method="post">
<input type="hidden" name="userid" value="96309001">
<input type="hidden" name="nocart"> 
<input type="hidden" name="producturl" value="http://www.fruitfulfarm.net/cart_2.html">
<input type="hidden" name="product" value="Test Product">
<input type="hidden" name="price" value="49.99">
<input type="hidden" name="return" 
value="www.fruitfulfarm.net/cart_2.html">
<input class="rounded" type="submit" name="submit" value="Add To Cart"
onclick="alert('Order has been added to your cart\n\nThis page will refresh');"
onkeypress="alert('Order has been added to your cart\n\nThis page will refresh');">
</form>        

最佳答案

使用onsubmit

HTML

<form method="post" action="" onsubmit="return myModal(this)">
    <!-- more inputs -->
    <input type="submit" value="Submit" />
</form>

JS

function myModal(f)
{
    var form=f,
        modal=$('<div/>', {
            'id':'alert',
            'html':'<iframe src="url"></iframe>'
        })
       .dialog({
           'title':'Iframe in a modal window',
           'modal':true,
           'width':350,
           'height':'auto',
           'buttons': {
               'OK': function() { 
                   $(this).dialog( "close" ); 
                   // do something, maybe call form.submit();
                }
            }
    });
    return false;
}

Example

关于jquery - 如何在提交 html 表单时打开 jQuery 模态窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14176270/

相关文章:

javascript - 触发模态

javascript - 当我悬停当前选项卡时更改其他选项卡的不透明度

javascript - 用javascript替换html内容

javascript - parsley.js 选择列表值为零 - 不起作用

HTML:在输入文本框中添加 <form> 标签将文本框置于网站 Logo 下方

javascript - 如何获取 jQuery 中文本节点内 anchor 的文本

Jquery - 使用列表焦点上的箭头键禁用窗口滚动

javascript - 尝试在表单中显示单选按钮的内容

html - Bootstrap, panel-footer with text align-center horizo​​ntally and vertically jump out 调整大小时

javascript - 如何在不破坏表单的情况下修复开关动画按钮以覆盖表单输入字段集