2014-11-04 49 views
1

我能够将变量传递到模式底部的引导程序3模式,它表示id =“callId”,但是如何将callID传递给模式,其中我有$ test = callId。将变量传递到Bootstrap模式

<a data-id="<?=$sid?>" data-conf="<?=$call_conf?>" class="open-AddCallDialog btn btn-success btn-xs" href="#addCallDialog">Call Borrower</a> 

jQuery的脚本

$(document).on("click", ".open-AddCallDialog", function (e) { 

    e.preventDefault(); 

    var _self = $(this); 

    var myCallId = _self.data('id'); 
    $("#callId").val(myCallId); 

    $(_self.attr('href')).modal('show'); 
}); 

模态

<div class="modal fade" id="addCallDialog"> 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">Call Borrower</h4> 
     </div> 
     <div class="modal-body"> 
     <div class="row well"> 
     $test = call_conf; 



     </div> 
     </div> 
     <div class="modal-footer"> 
     <input name="id" id="callId" type="hidden" value=""/> 
     <input name="pid" type="hidden" value="<?php echo $pid;?>"/> 
     <input name="processtp" type="hidden" value="callborrower"/> 
     <button id="submit" class="btn btn-primary btn-block btn-xs center">Update</button> 
     </div> 
     </form> 
     </div> 

    </div><!-- /.modal-content --> 
    </div><!-- /.modal-dialog --> 
+0

这对我来说不是很清楚。你能修复语法并解释你想获得什么吗? – 2014-11-04 08:29:25

回答

1

有创建引导模态时被解雇/摧毁了一些事件。

您需要的是shown.bs.modal,一旦显示模式并且所有的CSS3动画都完成,就会触发该模式。通过挂钩这个事件,你可以添加数据到模式的DOM结构。

$(document).on('click', '.openAddCallDialog', function(event) 
{ 
    var _self = $(this), 
     id = _self.data('id'), 
     conf = _self.data('conf'), 
     modalEl = $(_self.attr('href')); 

    modalEl.modal('show').one('shown.bs.modal', function(event) 
    {    
     // This function body is the modal shown event callback 
     // You can do anything in this function to modify the DOM 
     // within the shown modal. 

     var modal = $(this); 

     modal.find('#callId').val(callId); 

     modal.find('.well').text(conf); 
    });; 
} 
+0

我可以用这个脚本添加两个变量 – Richard 2014-11-04 09:17:11

+0

当然,只需获取需要的变量,然后将它们添加到回调中的模态。 – 2014-11-04 09:18:07

+0

我更改了上面的链接,添加了我想要添加的变量,并将其添加到我希望显示的模式中。对不起,我应该把这个放在我原来的问题中。我不明白你的回答,你在回调中说的地方。 – Richard 2014-11-04 09:30:52