【发布时间】:2016-05-13 12:16:03
【问题描述】:
演示和完整代码如下:https://jsfiddle.net/xzxrp7nn/5/
我的 HTML 代码是这样的:
<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 代码是这样的:
$(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);。
但是结果:priceModal={
有什么办法可以解决我的问题吗?
谢谢
【问题讨论】:
-
你的问题不是很清楚。您要发送或打印什么参数?
-
检查我的小提琴:
https://jsfiddle.net/xzxrp7nn/6/这是你想要的吗? -
检查这个小提琴,你不需要将 priceModel 添加到按钮 id 因为它可以直接在模型函数中使用检查这个jsfiddle.net/trd0q40e/1
-
你想要字符串中任何属性的值,还是你只是想直接打印孔字符串。
标签: javascript jquery json bootstrap-modal