模态打开时如何发送参数json数组? [英] How to send parameter json array when modal open?

查看:133
本文介绍了模态打开时如何发送参数json数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

演示和完整代码如下: https://jsfiddle.net/xzxrp7nn/5/

Demo and full code is like this : https://jsfiddle.net/xzxrp7nn/5/

我的HTML代码是这样的:

My HTML code is like this :

<div id="tes">

</div>


<!-- Modal Currency-->
<div class="modal fade" id="priceModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">


            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>

我的Javascript代码是这样的:

My Javascript code is like this :

$(document).ready(function(){

        var priceModal = '{"attributes":{"Code":"DBL","Total":"200000"},"DayPrice":{"Date":"2016-05-26","Rate":"200000"}}';

        var isitable = '<button class="btn blue tes_button" data-toggle="modal" data-target="#priceModal" id="priceModal='+priceModal+'">tes</button>';

        $("#tes").html(isitable);
        $('#priceModal').on('show.bs.modal', function(e) {
            var param = e.relatedTarget.id;
            console.log(param);
        })
    })

当打开模态时,我想获取参数priceModal。我在 $('#priceModal')。on('show.bs.modal',function(e)中执行 console.log(param); ){

When open modal, I want get parameter priceModal. I do console.log(param); in $('#priceModal').on('show.bs.modal', function(e) {.

但结果: priceModal = {

解决我问题的任何解决方案?

Any solution to solve my problem?

谢谢

推荐答案

JSFiddle

您使用的报价不正确:

 $(document).ready(function(){

        var priceModal = "{'attributes':{'Code':'DBL','Total':'200000'},'DayPrice':{'Date':'2016-05-26','Rate':'200000'}}";

        var isitable = '<button class="btn blue tes_button" data-toggle="modal" data-target="#priceModal" id="priceModal'+priceModal+'">tes</button>';

        $("#tes").html(isitable);
        $('#priceModal').on('show.bs.modal', function(e) {
            var param = e.relatedTarget.id;
            console.log(param);
        });
    });

这篇关于模态打开时如何发送参数json数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆