在按下提交表单后,如何在bootstrap模式中显示成功消息?

时间:2013-04-28 18:42:03

标签: javascript jquery html css twitter-bootstrap

我正在制作一个网站的原型,我试图让它看起来像一个人提交一个表单,用于在bootstrap模式中接收他们的信息。

我在页面顶部登录:

<div class="center-top-div">

        <form class="well inline-form" action="sidor/my_page.html" method="">
            <input type="text" class="span2" placeholder="Username">
            <input type="password" class="span2" placeholder="Password">
            <a href="sidor/index_inloggad.html" class="btn btn-small btn-primary pull-right" id="logga-in-btn">Log in</a><br>
            <a class="pull-right" id="amnesi" href="#myModal" data-toggle="modal">Forgotten?</a>
        </form>
    </div>

当有人按下“忘记?”链接时将显示一个模态:

<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-header">
           <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
           <h4 id="myModalLabel">Vi behöver din E-postadress!</h4>
        </div>
        <div class="modal-body">
            <form class="well inline-form larger-input">
                 <input class="input-large" type="text" class="span2" placeholder="Din E-postadress...">
                 <a href="//I WANT THIS TO LINK TO ANOTHER MODAL/GREETING MESSAGE" class="btn btn-small btn-primary pull-right" 
                    id="logga-in-btn">Get my details!</a><br>
            </form>
        </div>
        <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
        </div>
</div>

我想要发生的是,当一个人点击“获取我的详细信息!”时我想在模态或其他模态中显示问候语或其他内容。

任何想法将不胜感激! :)

/比尔

1 个答案:

答案 0 :(得分:1)

您需要使用事件委派来完成任何点击事件。看看这是否满足您的需求。这将在模态本身中显示消息。

<强> http://jsfiddle.net/spaXZ/

    $('body').on('click','#logga-in-btn' ,function(){
    $(this).closest('.modal-body').find('#grtmessage').remove().end().append($('<span id="grtmessage">Thank you, we have now email you your details</span>'));
});

如果您想要显示为模态,可以尝试: http://jsfiddle.net/HxrHd/