Kin*_*sin 5 javascript jquery modal-dialog twitter-bootstrap bootstrap-modal
使用bootstraps模式的示例
<div class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
Run Code Online (Sandbox Code Playgroud)
我想知道是否有办法实现这一点,某种动态通道jQuery.
我的目标是有一个类似变量的东西$theModal,它将被初始化并具有获取/设置标题的属性,内容,当点击保存/取消/关闭时要调用的javascipt函数等.
是应该通过jQuery代码生成还是应该在代码中生成标记并使用ids/custom data-attributes来捕获模态?
也许是一些阶级结构?
var $theModal = new MyModal();
Run Code Online (Sandbox Code Playgroud)
接下来的问题是,如果模态已经打开,如何创建克隆?
我想做/猜
var $theClone = $theModal.clone().init();
$theClone.title = "Title of the second modal";
$theClone.content = $.ajax(url);
$theClone.saveAction = saveTheContentOfTheContent;
$theClone.show();
Run Code Online (Sandbox Code Playgroud)
这是可能的还是我对我的假设完全错了?
你的想法还不错,但是……
您的 html 代码中可以有一个模式。然后在标题所在的空间中,您可以使用 $scope 类型。
然后,在 js 文件中,您可以在数组中指定所需的字符串,然后只需在 ng-click 函数的参数中更改为所需的字符串即可。
<p>This is the modal view.</p>
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">{{msgArray.title}}</h4>
</div>
<div class="modal-body">
<p>{{msgArray.body}}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{msgArray.btn}}</button>
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.msgArray1 = {
title : "Modal 1",
body: "This is the co to say anything you want here.",
btn : "Close",
};
$scope.msgArray2 = {
title : "Modal 2",
body: "This is the co to say anything you want here.",
btn : "Close",
};
$scope.msgTemp = {
title : "",
body: "",
btn : "",
};
$scope.openModal = function(modal){
if(modal == "modal1"){
$scope.msgTemp = $scope.msgArray1;
}
if(modal == "modal2"){
$scope.msgTemp = $scope.msgArray2;
}
$("#myModal").modal('show');
}
});
Run Code Online (Sandbox Code Playgroud)
http://plnkr.co/edit/nV3iq1U1ymcsBAXT6g2y?p=preview
| 归档时间: |
|
| 查看次数: |
475 次 |
| 最近记录: |