演示和完整的代碼是這樣的:https://jsfiddle.net/xzxrp7nn/5/如何在模態打開時發送參數json數組?
我的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。我做console.log(param);
在$('#priceModal').on('show.bs.modal', function(e) {
。
但結果:priceModal={
任何解決方案來解決我的問題呢?
謝謝
你的問題不是很清楚發生了什麼。你想要發送或打印什麼參數? –
檢查我的小提琴:'https:// jsfiddle.net/xzxrp7nn/6 /'這是你想要的嗎? – AlexIL
檢查此小提琴,您不需要將priceModel添加到按鈕ID,因爲它可以在模型函數內部直接使用檢查此https://jsfiddle.net/trd0q40e/1/ –