Bootstrap modal box pass value

Recently encountered a problem of modal frame transfer, took some detours, record it

My click on the button that appears the modal box:

<button data-toggle="modal" id="myModelfrom" data-target="#myModal onclick="Values('${u.payOrderNo}')">点击</button>

My modal box:

<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
        aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">信息</h4>
                </div>
                <div class="modal-body">
                    <form action="#" method="post" id="MyModalForm">
                        <div class="form-group">
                            <input type="text" class="form-control" id="invoiceNumber"
                                name="invoiceNumber" placeholder="请输入号码"> <input
                                type="hidden" name="orderNos" id="orderNos" /> <input
                                type="hidden" name="payNo" id="payNo" /> <input type="hidden"
                                name="page" id="page" value="payment" /> <input type="hidden"
                                name="invoiceSystem" id="invoiceSystem" />
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal"
                        id="flatAndOpenInvoice">确认</button>
                    <button type="button" class="btn btn-primary" data-dismiss="modal"
                        aria-hidden="true">取消</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal -->
    </div>

The next step is to pass the value:

$("#myModal").modal("hide");
    function Values(obj){
        $("#payNo").val(obj);
    } 

Then you can get the value of payNo

I just started using this and kept reporting an error: Many people on Baidu said that it was the problem of introducing jQuery first and then introducing bootstrap. But mine was originally jQuery introduced first. After exploring for a long time, it turned out that I put $("#myModal").modal ("hide");This is put in $(function(){}). So to summarize $("#myModal").modal("hide"); Don't put it in the $(function(){}) of jquery.

Guess you like

Origin blog.csdn.net/shuoshuo_12345/article/details/106378537