1

我是 jquery 的新手...刚开始学习它...

我遇到了一个问题,当我单击Open Model锚链接时,它会触发Open Modal div,它会给出一个包含Open Modal div内容的弹出窗口……代码如下……

  <a href="#opneModal"> Open Model </a>

<div id="openModal" class="modalDialog">
   <div>
    <a href="#close" title="Close" class="close">X</a>
    <h2>Congrats..</h2>
    <p>Now you can apply discount.</p>
   </div>
</div>

你可以看看这里的输出

到目前为止,一切正常。但现在我想在提交表单时打开弹出窗口(触发OpenModal div)......提交表单代码如下......

    <form action="" method="POST">
       <input type="text" name="name" required="" placeholder="Name" class="textbox"/>
       <input type="email" name="email" required="" placeholder="Email Address*" class="textbox"/>
      <input type="submit"  id="send" value="SUBMIT" class="button" />
    </form>

    $('form').submit(function(){
        //which code i should write which will call **OpenModal div**
    })

提前致谢

4

4 回答 4

1

到目前为止,一切正常。但现在我想在提交表单时打开弹出窗口(触发 OpenModal div)......提交表单代码如下......

我认为您说的是模态对话框

我创建了这个问题,我认为我错了标题,因为很难搜索它。我使用了 GET 方法,但我不知道这是否也可以使用 POST 方法,但您可以尝试。

现在我解释如何工作。

你使用这种形式,我说看到行动。

<form action="" method="POST" id="forma">
       <input type="text" name="name" required="" placeholder="Name" class="textbox"/>
       <input type="email" name="email" required="" placeholder="Email Address*" class="textbox"/>
      <input type="submit"  id="send" value="SUBMIT" class="button" />
    </form>

我建议你更换

<input type="submit"  id="send" value="SUBMIT" class="button" />

<input type="button" value="Clicca qui" onclick="start()" />

因为现在不发送表格。

我解释函数开始

function start() {
var $fm = $("#forma");
                $.post($fm.attr('you action is form'))
                    .done(function(data, ok){
                    var fr=$fm.serialize();
//now you can open the window popup and you can pass the variable fr or not. the important //that you not lose this contain of variable. When you close the window you say on server or //site that you go at address.
//With document.location.href="index2?"+fr; if you site is localhost:8100/index?bla=2&l=3
//document.location is localhost:8100 and document.location.href is the part index?bla=2&l=3
//then you have to go the localhost:8100/upload (look the action) you have to use
//document.location.href="upload?"+fr; 
//now I make the action 's form with this script


                    document.location.href="index2?"+fr;
                                    })
                    .fail(function(data){
                    alert('call failed');
                    // call failed for some reason -- add error messaging?
                    });

}
于 2013-11-12T10:06:15.403 回答
0
//then here is your code
$('form').submit(function(e){
        $('#openModal').fadeIn()
        e.preventDefault()
    })
于 2013-11-12T08:50:45.253 回答
0

你的 jquery 代码应该是这样的

$('form').submit( function(e) {
    $('a').trigger('click') //or open model directly
    e.preventDefault();
});
于 2013-11-12T08:51:02.790 回答
0

我想你想要(当你提交表单时,dialog将显示:

$('#send').click(function(foo){
     foo.preventDefault(); // you can remove this if you change #send type to button

     $('form').submit(function(){ // submit the form and show the dialog
        $('#mylink').click();
     })
});
于 2013-11-12T09:06:28.833 回答