将变量传递给Bootstrap模式

时间:2014-11-04 07:50:56

标签: javascript php jquery twitter-bootstrap

我能够将变量传递给模态底部的bootstrap 3模态,其中它表示id =“callId”但是如何将callID传递给我有$ test = callId的模态。

<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 -->

1 个答案:

答案 0 :(得分:1)

创建/销毁bootstrap模式时会触发一些事件。

一旦显示模态并且所有CSS3动画完成,您需要的是shown.bs.modal。通过挂钩此事件,您可以将数据添加到模态的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);
    });;
}