相关疑难解决方法(0)

如何使用jQuery打开Bootstrap模式窗口?

我正在使用Twitter Bootstrap模态窗口功能.当有人点击我的表单上的提交时,我想在单击表单中的"提交按钮"时显示模态窗口.

<form id="myform" class="form-wizard">
    <h2 class="form-wizard-heading">BootStap Wizard Form</h2>
    <input type="text" value=""/>
    <input type="submit"/>
</form>

<!-- Modal -->
<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>
        <h3 id="myModalLabel">Modal header</h3>
    </div>
    <div class="modal-body">
        <p>One fine body…</p>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
        <button class="btn btn-primary">Save changes</button>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

jQuery的:

$('#myform').on('submit', function(ev) {
    $('#my-modal').modal({
        show: 'false'
    }); 


    var data = $(this).serializeObject();
    json_data = JSON.stringify(data);
    $("#results").text(json_data); 
    $(".modal-body").text(json_data); 

    // $("#results").text(data);

    ev.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)

javascript jquery twitter-bootstrap

709
推荐指数
12
解决办法
153万
查看次数

将数据传递给bootstrap模式

我有几个超链接,每个超链接都附有一个ID.当我点击此链接时,我想打开一个模态(http://twitter.github.com/bootstrap/javascript.html#modals),并将此ID传递给模态.我搜索谷歌,但我找不到任何可以帮助我的东西.

这是代码:

<a data-toggle="modal" data-id="@book.Id" title="Add this item" class="open-AddBookDialog"></a>
Run Code Online (Sandbox Code Playgroud)

哪个应该打开:

<div class="modal hide" id="addBookDialog">
    <div class="modal-body">
        <input type="hidden" name="bookId" id="bookId" value=""/>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

有了这段代码:

$(document).ready(function () {
    $(".open-AddBookDialog").click(function () {
        $('#bookId').val($(this).data('id'));
        $('#addBookDialog').modal('show');
    });
});
Run Code Online (Sandbox Code Playgroud)

但是,当我单击超链接时,没有任何反应.当我给超链接一个href ="#addBookDialog"时,模态打开就好了,但它不包含任何数据.

我按照这个例子:如何将值参数传递给Bootstrap中的modal.show()函数

(我也试过这个:如何在模态对话框中设置输入值?)

javascript asp.net-mvc jquery twitter-bootstrap

484
推荐指数
9
解决办法
71万
查看次数